Blob Blame History Raw
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sun, 30 Jan 2022 15:18:03 +0100
Subject: [PATCH] Explicitly add fPIC and DPIC for gcc

This addresses linking on Fedora 34 and later with gcc 11:

```
gcc -shared -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -Wl,-O2 -Wl,-E   alarm_checks.o hashTable.o interprocess_buffer.o openserMIBNotifications.o openserObjects.o openserSIPCommonObjects.o openserSIPContactTable.o openserSIPMethodSupportedTable.o openserSIPPortTable.o openserSIPRegUserLookupTable.o openserSIPRegUserTable.o openserSIPServerObjects.o openserSIPStatusCodesTable.o snmpstats.o sub_agent.o utilities.o  -L/usr/lib64 -lnetsnmpmibs -lnetsnmpagent -lnetsnmp -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -lm -lsensors -ldl -lm -lrpm -lrpmio -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -lm -lssl -lssl -lcrypto  -o snmpstats.so
/usr/bin/ld: /tmp/cccfDV1K.ltrans0.ltrans.o: warning: relocation against `event_shm_threshold' in read-only section `.text'
/usr/bin/ld: /tmp/cccfDV1K.ltrans0.ltrans.o: relocation R_X86_64_PC32 against undefined symbol `ctime_buf' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[1]: Leaving directory '/builddir/build/BUILD/opensips-3.1.7/modules/snmpstats'
make[1]: *** [../../Makefile.rules:39: snmpstats.so] Error 1
make: *** [Makefile:197: modules] Error 2
```

Closes #2734.

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>

diff --git a/Makefile.defs b/Makefile.defs
index c87ab08a8..0ec6220d4 100644
--- a/Makefile.defs
+++ b/Makefile.defs
@@ -1326,7 +1326,7 @@ ifeq		($(LDTYPE), solaris)
 else
 		#gcc and maybe others, => gnu ld
 		LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
-		MOD_LDFLAGS=-shared $(LDFLAGS)
+		MOD_LDFLAGS=-shared -fPIC -DPIC $(LDFLAGS)
 endif
 endif
 ifeq    ($(CC_NAME), clang)
@@ -1358,7 +1358,7 @@ ifeq		($(LDTYPE), solaris)
 else
 			#gnu or other ld type
 			LDFLAGS+=-Wl,-E $(PROFILE)
-			MOD_LDFLAGS=-shared $(LDFLAGS)
+			MOD_LDFLAGS=-shared -fPIC -DPIC $(LDFLAGS)
 endif
 endif
 ifeq	($(CC_NAME), icc)