[PATCH] gmp: compile with -DPIC to use correct asm code
Eneas U de Queiroz
cotequeiroz at gmail.com
Thu Mar 11 21:46:33 GMT 2021
The library is always compiled with $(FPIC) (-fPIC or -fpic), even for
the static library.
There are some assembly sources that decide whether or not to enable
PIC code by checking if PIC is defined. It counts on libtool to define
it, but libtool does it only when producing code for the dynamic
library, while we need it for both.
Ensure it is defined by adding it to CFLAGS next to $(FPIC).
It avoids linking errors with strongswan on x86_64:
ld: libgmp.a(bdiv_q_1.o): relocation R_X86_64_PC32 against symbol
`__gmp_binvert_limb_table' can not be used when making a shared object;
recompile with -fPIC
Cc: Stijn Tintel <stijn at linux-ipv6.be>
Signed-off-by: Eneas U de Queiroz <cotequeiroz at gmail.com>
---
There's an error on one architecture, and all others work fine without
this, so I'm uneasy changing this and then breaking stuff that was
working fine otherwise. However, it feels wrong to me to generate PIC
code from C files, but not use it in asm sources, which is essentially
what I am changing here.
I've looked at asm sources for different chitectures, and there are
checks for PIC in: arm64, arm, x86_64, x86, and ppc asm sources, but the
error only appears on x86_64.
For most CPUs, ifdef(`PIC'), is just used to do different definitions of
LEA (Load Effective Address). However, both x86 and x86_64 have many
other checks.
I've looked at bdiv_q_1.asm for different CPUs, and they all do some
form of LEA(binvert_limb_table), except for x86, where it will do it
only when PIC is defined. That may explain why x86_64 is affected, and
x86 is not.
I have not investigated further details.
Alternatively, we can define it only for x86_64, which is where we know
there's a build failure with the linker asking to recompile with -fPIC.
package/libs/gmp/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/package/libs/gmp/Makefile b/package/libs/gmp/Makefile
index eb7d808139..d59e8fe947 100644
--- a/package/libs/gmp/Makefile
+++ b/package/libs/gmp/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=gmp
PKG_VERSION:=6.2.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)$(PKG_REVISION).tar.xz
PKG_SOURCE_URL:=@GNU/gmp/
@@ -38,7 +38,7 @@ define Package/libgmp/description
signed integers, rational numbers, and floating point numbers.
endef
-TARGET_CFLAGS += $(FPIC)
+TARGET_CFLAGS += -DPIC $(FPIC)
CONFIGURE_VARS += CC="$(TARGET_CROSS)gcc"
CONFIGURE_ARGS += \
--enable-shared \
More information about the openwrt-devel
mailing list