pdfalto icon indicating copy to clipboard operation
pdfalto copied to clipboard

recompile with -fPIC

Open rytis-paskauskas opened this issue 6 years ago • 34 comments

$ make ... [ 15%] Linking CXX executable pdfalto /usr/bin/ld: libs/image/png/linux/libpng.a(png.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC ....

$ cc -v Using built-in specs. COLLECT_GCC=cc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto Thread model: posix gcc version 8.2.1 20181127 (GCC)

Any ideas? Thanks, Rytis

rytis-paskauskas avatar Jan 18 '19 15:01 rytis-paskauskas

Thank you for this feedback. Could send the output of this command :

uname -i

Aazhar avatar Jan 18 '19 15:01 Aazhar

you need to generate build file using the flag PIC as showed in the error. So you need to run cmake this way :

cmake "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true" .

Aazhar avatar Jan 18 '19 16:01 Aazhar

Sorry but this didn't work for me: $ make clean; $ cmake "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true" ./; make .... [ 15%] Linking CXX executable pdfalto /usr/bin/ld: libs/image/png/linux/libpng.a(png.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC ...

On Fri, Jan 18, 2019 at 5:06 PM Aazhar [email protected] wrote:

you need to generate build file using the flag PIC as showed in the error. So you need to run cmake this way :

cmake "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true" .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kermitt2/pdfalto/issues/41#issuecomment-455598047, or mute the thread https://github.com/notifications/unsubscribe-auth/ARkHE7zrjK26RXHLeMBmwZdYhslVsPn_ks5vEfEEgaJpZM4aIKVL .

rytis-paskauskas avatar Jan 20 '19 17:01 rytis-paskauskas

$ uname -i unknown $ uname -a Linux ... 4.19.13-1-lts #1 SMP Sun Dec 30 07:38:47 CET 2018 x86_64 GNU/Linux

rytis-paskauskas avatar Jan 20 '19 17:01 rytis-paskauskas

Thanks for the information, I can't reproduce this error in my environment, but I think you need to regenerate the libpng.a. To do so you to go under libs/image/png/src and run :

cmake "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true" ./; make

This will generate a libpng.a file that you need to copy under libs/image/png/linux , since I understand you are using linux.

Please keep me informed.

Aazhar avatar Jan 20 '19 18:01 Aazhar

It appears your suggestion was correct. I can't see the libpng errors anymore but there are still many similar errors from the other libs:

[15%] Linking CXX executable pdfalto /usr/bin/ld: libs/libxml/linux/libxml2.a(entities.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC

... I couldn't apply the same fix to the remaining libs as the other sources aren't available.

On Sun, Jan 20, 2019 at 7:53 PM Aazhar [email protected] wrote:

Thanks for the information, I can't reproduce this error in my environment, but I think you need to regenerate the libpng.a. To do so you to go under libs/image/png/src and run :

cmake "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true" ./; make

This will generate a libpng.a file that you need to copy under libs/image/png/linux , since I understand you are using linux.

Please keep me informed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kermitt2/pdfalto/issues/41#issuecomment-455892123, or mute the thread https://github.com/notifications/unsubscribe-auth/ARkHE4e71vclFC-p4JvQHr4e7_tzQ6FIks5vFLsUgaJpZM4aIKVL .

rytis-paskauskas avatar Jan 21 '19 22:01 rytis-paskauskas

Could you update your repository and re make it.

Aazhar avatar Jan 22 '19 10:01 Aazhar

Back to square one I'm afraid. I compiled the libpng and libzlib with your earlier flag suggestion. Here is the full error message. [ 15%] Linking CXX executable pdfalto /usr/bin/ld: libs/image/png/linux/libpng.a(png.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/png/linux/libpng.a(pngerror.c.o): relocation R_X86_64_32S against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/png/linux/libpng.a(pngmem.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/png/linux/libpng.a(pngset.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/png/linux/libpng.a(pngtrans.c.o): relocation R_X86_64_32S against .data' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/png/linux/libpng.a(pngwio.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/png/linux/libpng.a(pngwrite.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/png/linux/libpng.a(pngwutil.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(crc32.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(deflate.c.o): relocation R_X86_64_32S against symbol zcalloc' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(inflate.c.o): relocation R_X86_64_32S against symbol zcalloc' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(inftrees.c.o): relocation R_X86_64_32S against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(trees.c.o): relocation R_X86_64_32S against .data' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(zutil.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(compress.c.o): relocation R_X86_64_32 against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/image/zlib/linux/libzlib.a(inffast.c.o): relocation R_X86_64_32S against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(uobject.ao): relocation R_X86_64_32S against symbol _ZN6icu_627UObjectD0Ev' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(cmemory.ao): relocation R_X86_64_32 against .rodata._ZL7zeroMem' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(unistr.ao): relocation R_X86_64_32 against .bss._ZZN6icu_6213UnicodeString16getStaticClassIDEvE7classID' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(ustring.ao): relocation R_X86_64_32S against .rodata._ZL12UNESCAPE_MAP' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(ustrtrns.ao): relocation R_X86_64_32S against .rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(loadednormalizer2impl.ao): relocation R_X86_64_32S against symbol _ZTVN6icu_6221LoadedNormalizer2ImplE' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(utrie2.ao): relocation R_X86_64_32 against .text._ZL13enumSameValuePKvj' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(uinvchar.ao): relocation R_X86_64_32S against .rodata._ZL14invariantChars' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(umutex.ao): relocation R_X86_64_32 against .bss._ZL11globalMutex' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(ucln_cmn.ao): relocation R_X86_64_32 against .bss._ZL20gLibCleanupFunctions' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(udata.ao): relocation R_X86_64_32 against .bss._ZL19gCommonICUDataArray' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(ucmndata.ao): relocation R_X86_64_32S against .rodata._ZL9ToCPFuncs' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(udataswp.ao): relocation R_X86_64_32 against .rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(utrace.ao): relocation R_X86_64_32S against .rodata._ZZL14outputHexBytesliPcPiiE9gHexChars' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(uhash.ao): relocation R_X86_64_32S against .rodata._ZL6PRIMES' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(appendable.ao): relocation R_X86_64_32S against symbol _ZTVN6icu_6210AppendableE' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(utf_impl.ao): relocation R_X86_64_32S against .rodata' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(normalizer2impl.ao): relocation R_X86_64_32 against .text.enumLcccRange' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(normalizer2.ao): relocation R_X86_64_32S against symbol _ZTVN6icu_6211Normalizer2E' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(utrie2_builder.ao): relocation R_X86_64_32 against .text._ZL13copyEnumRangePKviij' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(uniset.ao): relocation R_X86_64_32 against .bss._ZZN6icu_6210UnicodeSet16getStaticClassIDEvE7classID' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(unifilt.ao): relocation R_X86_64_32 against .bss._ZZN6icu_6213UnicodeFilter16getStaticClassIDEvE7classID' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(unifunct.ao): relocation R_X86_64_32 against .bss._ZZN6icu_6214UnicodeFunctor16getStaticClassIDEvE7classID' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(util.ao): relocation R_X86_64_32S against .rodata._ZL6DIGITS' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(putil.ao): relocation R_X86_64_32 against .rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(charstr.ao): relocation R_X86_64_32 against symbol __gxx_personality_v0' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(ucol_swp.ao): relocation R_X86_64_32 against .rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(uvector.ao): relocation R_X86_64_32 against .bss._ZZN6icu_627UVector16getStaticClassIDEvE7classID' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(edits.ao): relocation R_X86_64_32 against .rodata.str2.2' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(patternprops.ao): relocation R_X86_64_32S against .rodata._ZN6icu_62L6latin1E' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(utrie.ao): relocation R_X86_64_32 against .text._ZL21defaultGetFoldedValueP8UNewTrieii' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(bmpset.ao): relocation R_X86_64_32S against symbol _ZTVN6icu_626BMPSetE' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: libs/icu/linux/libicuuc.a(unisetspan.ao): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: final link failed: nonrepresentable section on output collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/pdfalto.dir/build.make:184: pdfalto] Error 1 make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/pdfalto.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

On Tue, Jan 22, 2019 at 11:48 AM Aazhar [email protected] wrote:

Could you update your repository and re make it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kermitt2/pdfalto/issues/41#issuecomment-456355224, or mute the thread https://github.com/notifications/unsubscribe-auth/ARkHE0W04251AyhtAwZehifRc0OXWX06ks5vFuxugaJpZM4aIKVL .

rytis-paskauskas avatar Jan 22 '19 18:01 rytis-paskauskas

Ok, it seems that your linker is old. Could you send the output of this

ld -v

Aazhar avatar Jan 23 '19 13:01 Aazhar

What I suggest is you checkout the last updates and you compile the dependencies following the description here : https://github.com/kermitt2/pdfalto/blob/master/Dependencies_INSTALL.md

Aazhar avatar Jan 23 '19 13:01 Aazhar

$ ld -v GNU ld (GNU Binutils) 2.31.1

I think you'll agree that my linker is not 'old'.

Thanks for writing up the 'do it yourself' instructions even though the approach is hardly ideal to solve one's software's portability issues.

rytis-paskauskas avatar Jan 24 '19 21:01 rytis-paskauskas

I've a bash script for installing the dependencies in one step , you can recompile all of the dependencies using this bash script https://github.com/kermitt2/pdfalto/blob/master/install_deps.sh

Aazhar avatar Jan 29 '19 11:01 Aazhar

Hello, Any updates about this issue, have you installed the dependencies using the shell script ?

Aazhar avatar Feb 18 '19 11:02 Aazhar

On Arch Linux I have the same issue, to use the provided libs I used an ubuntu:16.04 container:

docker run -v $PWD:/mnt --rm -it ubuntu:16.04 bash -c "apt-get update -qq; apt-get install -qq cmake build-essential clang git; git clone --depth=50 --branch=master https://github.com/kermitt2/pdfalto.git --recursive; (cd pdfalto; cmake ./; make; cp pdfalto /mnt);" && sudo chown $(id -u):$(id -g) pdfalto

naufraghi avatar Feb 18 '19 11:02 naufraghi

If you are encountering the same issue regarding the dependencies please refer to this section : https://github.com/kermitt2/pdfalto#dependencies To fix this issue you'll need to run this script : https://github.com/kermitt2/pdfalto/blob/master/install_deps.sh

Aazhar avatar Feb 18 '19 11:02 Aazhar

hello @rytis-paskauskas Could you give some updates about this issue

Aazhar avatar Mar 04 '19 15:03 Aazhar

Hi, sorry for the delay. To make it up for it, I ran two OSs: Arch and the latest Debian. Following a clean checkout. Arch: failed (libpaper) Debian: success

Here is the relevant output on Arch: $ cmake ./ ++ 64 bit architecture -- Found FreeType (old-style includes): /opt/src/pdfalto/libs/freetype/linux/64/libfreetype.a -- lcms2 not found -- Configuring done -- Generating done -- Build files have been written to: /opt/src/pdfalto

$ ./install_deps.sh ..... lots of warnings but no errors

$ make [ 36%] Built target xpdf [ 42%] Built target goo_objs [ 43%] Built target goo [ 48%] Built target fofi_objs [ 48%] Built target fofi [ 60%] Built target splash_objs [ 61%] Built target splash [ 62%] Linking CXX executable pdfalto /usr/bin/ld: xpdf-4.00/build/xpdf/lib/libxpdf.a(GlobalParams.cc.o): in function GlobalParams::GlobalParams(char const*)': GlobalParams.cc:(.text+0xd81): undefined reference to paperinit' /usr/bin/ld: GlobalParams.cc:(.text+0xd86): undefined reference to systempapername' /usr/bin/ld: GlobalParams.cc:(.text+0xda2): undefined reference to paperinfo' /usr/bin/ld: GlobalParams.cc:(.text+0xdb2): undefined reference to paperpswidth' /usr/bin/ld: GlobalParams.cc:(.text+0xdc9): undefined reference to paperpsheight' /usr/bin/ld: GlobalParams.cc:(.text+0xe0e): undefined reference to `paperdone' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/pdfalto.dir/build.make:184: pdfalto] Error 1 make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/pdfalto.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

[rytis@pappa pdfalto] $ pacman -Ss libpaper extra/libpaper 1.1.24-11 [installed] Library for handling paper characteristics $ pacman -Ql libpaper libpaper /etc/ libpaper /etc/libpaper.d/ libpaper /etc/papersize libpaper /usr/ libpaper /usr/bin/ libpaper /usr/bin/paperconf libpaper /usr/bin/paperconfig libpaper /usr/include/ libpaper /usr/include/paper.h libpaper /usr/lib/ libpaper /usr/lib/libpaper.so libpaper /usr/lib/libpaper.so.1 libpaper /usr/lib/libpaper.so.1.1.2 ....

On Debian all went well.

rytis-paskauskas avatar Mar 05 '19 17:03 rytis-paskauskas

Thanks for your feedback, I've corrected it, it should be ok by now.

Aazhar avatar Mar 06 '19 11:03 Aazhar

Hi @Aazhar

I'm getting the same error actually. The script execution ends up with:

Copying libraries into their corresponding location.
cp: cannot stat 'install/libxml2-2.9.8/.libs/libxml2.a': No such file or directory
done.

Vitaliy-1 avatar Mar 27 '19 20:03 Vitaliy-1

During the process

Checking zlib
./configure: line 13059: syntax error near unexpected token `Z,zlib,'
./configure: line 13059: `        PKG_CHECK_MODULES(Z,zlib,'
make: *** No targets specified and no makefile found.  Stop.
libxml2 installation is finished.

Vitaliy-1 avatar Mar 27 '19 20:03 Vitaliy-1

Nevermind. sudo apt install pkg-config

Vitaliy-1 avatar Mar 27 '19 20:03 Vitaliy-1

Hi, I was having the same "relocation R_X86_64_32 against" errors. I'm on Debian stretch:

vagrant@stretch:~/git/pdfalto$ uname -a
Linux stretch 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3 (2019-02-02) x86_64 GNU/Linux

I think all errors are from trying to link the libicuuc.a static library:

/usr/bin/ld: libs/icu/linux/64/libicuuc.a(uobject.ao): relocation R_X86_64_32 against symbol `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(cmemory.ao): relocation R_X86_64_32 against `.rodata._ZL7zeroMem' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(unistr.ao): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(ustring.ao): relocation R_X86_64_32S against `.rodata._ZL12UNESCAPE_MAP' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(ustrtrns.ao): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
.. many more ..

I did use the install_deps.sh script, so I didn't know how to solve this with a pie executable. Therefore I tried another solution, I added this to CMakeLists.txt:

   set(CMAKE_EXE_LINKER_FLAGS "-no-pie")

And this solved my problem:-)

cassebas avatar Apr 04 '19 12:04 cassebas

set(CMAKE_EXE_LINKER_FLAGS "-no-pie") is not working for me i am getting the same error

/usr/bin/ld: /usr/local/lib/libbcrypt.a(wrapper.c.o): relocation R_X86_64_PC32 against symbol `_crypt_itoa64' can not be used when making a shared object; recompile with -fPIC

nisharepo avatar Jun 17 '20 20:06 nisharepo

Hi, I was having the same "relocation R_X86_64_32 against" errors. I'm on Debian stretch:

vagrant@stretch:~/git/pdfalto$ uname -a
Linux stretch 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3 (2019-02-02) x86_64 GNU/Linux

I think all errors are from trying to link the libicuuc.a static library:

/usr/bin/ld: libs/icu/linux/64/libicuuc.a(uobject.ao): relocation R_X86_64_32 against symbol `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(cmemory.ao): relocation R_X86_64_32 against `.rodata._ZL7zeroMem' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(unistr.ao): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(ustring.ao): relocation R_X86_64_32S against `.rodata._ZL12UNESCAPE_MAP' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(ustrtrns.ao): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
.. many more ..

I did use the install_deps.sh script, so I didn't know how to solve this with a pie executable. Therefore I tried another solution, I added this to CMakeLists.txt:

   set(CMAKE_EXE_LINKER_FLAGS "-no-pie")

And this solved my problem:-)

I was facing the same issue with other project

Hi, I was having the same "relocation R_X86_64_32 against" errors. I'm on Debian stretch:

vagrant@stretch:~/git/pdfalto$ uname -a
Linux stretch 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3 (2019-02-02) x86_64 GNU/Linux

I think all errors are from trying to link the libicuuc.a static library:

/usr/bin/ld: libs/icu/linux/64/libicuuc.a(uobject.ao): relocation R_X86_64_32 against symbol `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(cmemory.ao): relocation R_X86_64_32 against `.rodata._ZL7zeroMem' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(unistr.ao): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(ustring.ao): relocation R_X86_64_32S against `.rodata._ZL12UNESCAPE_MAP' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libs/icu/linux/64/libicuuc.a(ustrtrns.ao): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
.. many more ..

I did use the install_deps.sh script, so I didn't know how to solve this with a pie executable. Therefore I tried another solution, I added this to CMakeLists.txt:

   set(CMAKE_EXE_LINKER_FLAGS "-no-pie")

And this solved my problem:-)

Lifesaver. I was facing the same issue with another project. set(CMAKE_EXE_LINKER_FLAGS "-no-pie") 💯 👍

prashantsathe avatar Aug 05 '20 08:08 prashantsathe

Using a clean environment in docker I get exactly the same error. This is the sript I am executing

FROM debian:buster-slim as builder


RUN DEBIAN_FRONTEND=noninteractive \
    apt-get update && \
    apt-get install -y --no-install-recommends \
        ca-certificates wget sudo autoconf automake pkg-config cmake build-essential clang git && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN git config --global url."https://github.com/".insteadOf [email protected]: && \
    git clone --depth=50 --branch=master https://github.com/kermitt2/pdfalto.git --recursive

WORKDIR pdfalto
RUN ./install_deps.sh
RUN cmake ./ && make

mcuadros avatar Jun 09 '21 09:06 mcuadros

Aeh, you are downloading static libraries (usually illegal on many distros) and just linking against a libxml.a built with whatever flags? This will totally not work and injects binary artifacts checked in into git of unknown source into the build!

Please link against the system libxml2 (which links against the correct system icu) or compile all sources from scratch as subprojects (but why would you want to do that? If your version of xpdf is relying on old versions of standard libraries you should consider adapting the code).

This applies for all other libraries too:

set ( XML_LIBRARY ${XML_LIB_SUBDIR}/${OSSUFFIX}/${ARCHSUFFIX}/libxml2.a)
set ( PNG_LIBRARIES ${PNG_SUBDIR}/${OSSUFFIX}/${ARCHSUFFIX}/libpng.a)
set ( ZLIB_LIBRARY ${ZLIB_SUBDIR}/${OSSUFFIX}/${ARCHSUFFIX}/libzlib.a)
set ( FREETYPE_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/libs/freetype/${OSSUFFIX}/${ARCHSUFFIX}/libfreetype.a)
set ( ICUUC_LIB ${CMAKE_CURRENT_SOURCE_DIR}/libs/icu/${OSSUFFIX}/${ARCHSUFFIX}/libicuuc.a)
set ( ICUDATA_LIB ${CMAKE_CURRENT_SOURCE_DIR}/libs/icu/${OSSUFFIX}/${ARCHSUFFIX}/libicudata.a)

andreasbaumann avatar Jan 17 '22 12:01 andreasbaumann

Ok, I tried to patch and package it for Archlinux, so that it builds fine with system libraries. The result is here: https://aur.archlinux.org/packages/pdfalto/

andreasbaumann avatar Jan 17 '22 14:01 andreasbaumann

Thank you @andreasbaumann for your message

In this build, we are not trying to make a linux redistribution package that will be further linked by other library (it would be another build scenario). Here we are building a standalone executable to be portable and packaged in other tools (to avoid having the users of these tools to install pdfalto on their system and deal with library compatibility).

So our motivation here is not to link dynamically with the system libraries and not building something to be further linked with something else (afaik there is compiler and flag compatibility issues in this case).

you are downloading static libraries (usually illegal on many distros)

Could you elaborate why it would be illegal or point to some explanations? To my understanding, there is no problem to add to a GitHub repo some static libraries built from GPL compatible sources in a GPL project.

... injects binary artifacts checked in into git of unknown source into the build

The sources correspond to the script https://github.com/kermitt2/pdfalto/blob/master/install_deps.sh Again the goal here is to facilitate a static build that can be embedded in other tools with minimal dependencies, not to create a linux package.

kermitt2 avatar Jan 17 '22 14:01 kermitt2

Well, illegal is a harsh term, sorry. :-)

Statically linked libraries have been built with all kind of flags affecting the ABI (PIC, PIE, stack smashing, optimization flags, etc.), so it might not link on the target machine or expose strange behaviour.

Static libraries might pose a security risk, imagine a vulnerabilty gets fixed in libpng, but you still link statically against an old version containing the vulerability.

The whole idea of doing packaging of software is to easy the installation for normal Linux users. But you leave the last step of linking and building pdfalto to the end user, which results in the errors as seen above.

You end up in bitrot (for instance your C++ code depends on old deprecated APIs of libpng), which is not good for the code quality on the long term.

andreasbaumann avatar Jan 17 '22 15:01 andreasbaumann

@andreasbaumann So "bad practices" rather than illegal, I feel better with that :)

Thanks a lot for the Archlinux package, this is great contribution! Could you maybe suggest some notes about it to be added in the readme? Or I can just point to https://aur.archlinux.org/packages/pdfalto/ ?

I totally agree with you about packaging and that a statically link library is very bad distributable, sure. But this build was not intended for distributing a library, it's for building an executable that can work on a variety of outdated linux distro 64 bits and macos without any install for the end user (most would not do it). This is the scenario we needed pdfalto, which explains why we focused on it.

For doing this, I don't see how we can avoid freezing the dependencies as static libraries, this is pro and cons of static vs dynamic. Would you have suggestions how to improve building a portable executable ?

kermitt2 avatar Jan 17 '22 15:01 kermitt2