[gdb/build] Fix gdbserver build with -fsanitize=address
authorTom de Vries <tdevries@suse.de>
Thu, 7 Jan 2021 09:37:51 +0000 (10:37 +0100)
committerTom de Vries <tdevries@suse.de>
Thu, 7 Jan 2021 09:37:51 +0000 (10:37 +0100)
When doing a gdbserver build with CFLAGS/CXXFLAGS/LDFLAGS=-fsanitize=address
we run into:
...
ld: ../libiberty/libiberty.a(safe-ctype.o):
relocation R_X86_64_32 against `.data' can not be used when making a
shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status
make[1]: *** [libinproctrace.so] Error 1
...

This started with commit 96648494173 "gdbsupport: make use of safe-ctype
functions from libiberty", which introduced a dependency of libinproctrace.so
on libiberty.

Fix this in gdbserver/Makefile.in by using a setup similar to what is done in
gcc-repo/src/libcc1/Makefile.am, such that ../libiberty/noasan/libiberty.a is
used instead.

Build on x86_64-linux, both with and without -fsanitize=address.

gdbserver/ChangeLog:

2021-01-07  Tom de Vries  <tdevries@suse.de>

* Makefile.in (LIBIBERTY_NORMAL, LIBIBERTY_NOASAN, LIBIBERTY_PIC):
(LIBIBERTY_FOR_SHLIB): New var.
(LIBIBERTY): Set using $(LIBIBERTY_NORMAL).
(IPA_LIB): Use LIBIBERTY_FOR_SHLIB instead of LIBIBERTY in target rule.

gdbserver/ChangeLog
gdbserver/Makefile.in

index 6c7738e8077efc078d4b598a0c9df83d7156cc98..3323ecfbf895c4f03c10d0e664517eebf418b4b9 100644 (file)
@@ -1,3 +1,10 @@
+2021-01-07  Tom de Vries  <tdevries@suse.de>
+
+       * Makefile.in (LIBIBERTY_NORMAL, LIBIBERTY_NOASAN, LIBIBERTY_PIC):
+       (LIBIBERTY_FOR_SHLIB): New var.
+       (LIBIBERTY): Set using $(LIBIBERTY_NORMAL).
+       (IPA_LIB): Use LIBIBERTY_FOR_SHLIB instead of LIBIBERTY in target rule.
+
 2021-01-04  Simon Marchi  <simon.marchi@efficios.com>
 
        * debug.cc (debug_print_depth): New.
index a2fe302d247131e252af8a7ad59c3b7ca3a79ab0..a14d3a7bc18fbd75330e1eb427c6d484c2304f9c 100644 (file)
@@ -103,7 +103,16 @@ INCLUDE_DIR = ${srcdir}/../include
 INCLUDE_DEP = $$(INCLUDE_DIR)
 
 LIBIBERTY_BUILDDIR = ../libiberty
-LIBIBERTY = $(LIBIBERTY_BUILDDIR)/libiberty.a
+LIBIBERTY_NORMAL = $(LIBIBERTY_BUILDDIR)/libiberty.a
+LIBIBERTY_NOASAN = $(LIBIBERTY_BUILDDIR)/noasan/libiberty.a
+LIBIBERTY_PIC = $(LIBIBERTY_BUILDDIR)/pic/libiberty.a
+LIBIBERTY_FOR_SHLIB = \
+  $(if $(wildcard $(LIBIBERTY_NOASAN)),\
+       $(LIBIBERTY_NOASAN),\
+       $(if $(wildcard $(LIBIBERTY_PIC)),\
+           $(LIBIBERTY_PIC),\
+           $(LIBIBERTY_NORMAL)))
+LIBIBERTY = $(LIBIBERTY_NORMAL)
 
 GDBSUPPORT_BUILDDIR = ../gdbsupport
 GDBSUPPORT = $(GDBSUPPORT_BUILDDIR)/libgdbsupport.a
@@ -395,7 +404,7 @@ $(IPA_LIB): $(sort $(IPA_OBJS)) ${CDEPS}
        $(ECHO_CXXLD) $(CC_LD) -shared -fPIC -Wl,--soname=$(IPA_LIB) \
                -Wl,--no-undefined $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
                 $(CXXFLAGS) \
-               -o $(IPA_LIB) ${IPA_OBJS} $(LIBIBERTY) -ldl -pthread
+               -o $(IPA_LIB) ${IPA_OBJS} $(LIBIBERTY_FOR_SHLIB) -ldl -pthread
 
 # Put the proper machine-specific files first, so M-. on a machine
 # specific routine gets the one for the correct machine.