wbhart / mpir

Multiple Precision Integers and Rationals
GNU General Public License v3.0
229 stars 135 forks source link

__gmp_modlimb_invert_table can not be used when making a shared object #286

Open madebr opened 4 years ago

madebr commented 4 years ago

Building a shared z3 library with mpir as a replacement for gmp fails because __gmp_modlimb_invert_table does not support relocation.

The link error is:

/usr/bin/ld: /home/maarten/.conan/data/mpir/3.0.0/_/_/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/lib/libgmp.a(modexact_1c_odd.o): relocation R_X86_64_PC32 against symbol `__gmp_modlimb_invert_table' can not be used when making a shared object; recompile with -fPIC

Reference to the source: https://github.com/wbhart/mpir/blob/master/mpn/x86_64/modexact_1c_odd.as#L58-L88

ZHOUYue67 commented 4 years ago

I have the exact same issue when building a shared library depending on CGAL & MPIR.

amakhno commented 4 years ago

Hi! The same bug here

leleliu008 commented 7 months ago

I greped the source code and found that some NASM assembly code using %ifdef PIC

./mpn/x86_64w/sqr_basecase.asm:11:  %ifdef PIC
./mpn/x86_64w/sqr_basecase.asm:20:  %ifdef PIC
./mpn/x86_64/netburst/sub_n.as:122:%ifdef PIC
./mpn/x86_64/netburst/sub_n.as:134:%ifdef PIC
./mpn/x86_64/netburst/add_n.as:122:%ifdef PIC
./mpn/x86_64/netburst/add_n.as:134:%ifdef PIC
./mpn/x86_64/modexact_1c_odd.as:107:%ifdef PIC

but build system doesn't pass -D PIC to yasm command, so we make sure -D PIC is passed to yasm command by:

YASM="$(command -v yasm)"                                                                                                                        

cat > yasm <<EOF                                                                                                                          
#!/bin/sh
exec "$YASM" -D PIC "\$@"
EOF

chmod +x yasm

export PATH="$PWD:$PATH"

resolved this problem.