[PR,gdb/23985] Fix libinproctrace.so build

Message ID c5aa7f3c-a323-c1f3-7f98-719c976eda3a@arm.com
State New, archived
Headers

Commit Message

Szabolcs Nagy Dec. 14, 2018, 6:03 p.m. UTC
  The IPA objects currently may use gnulib replacement apis, which is
wrong: gnulib is not linked into the produced dso and it cannot be
because it is not built with -fPIC -fvisibility=hidden.

The gnulib replacement detection is broken under cross compilation:
for targets other than *-gnu*, replacements are enabled that depend
on execution time detection. This causes unnecessary build failure
when the target has proper support for the replaced api.

This fix tries to undo the replacements, which is tricky because the
gnulib headers are still used for various compile time fixups and
there is no simple knob in gnulib to only turn the replacements off.

Without this workaround gdb fails to cross build to non-gnu targets:

  ld: tracepoint-ipa.o: in function `gdb_agent_helper_thread(void*)':
  gdb/gdbserver/tracepoint.c:7221: undefined reference to `rpl_strerror'
  ...
  Makefile:434: recipe for target 'libinproctrace.so' failed

gdb/gdbserver/ChangeLog:

2018-12-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR gdb/23985
	* Makefile.in (IPAGENT_CFLAGS): Add UNDO_GNULIB_CFLAGS.
	(UNDO_GNULIB_CFLAGS): Undo gnulib replacements.
  

Comments

Szabolcs Nagy Jan. 9, 2019, 2:51 p.m. UTC | #1
On 14/12/2018 18:03, Szabolcs Nagy wrote:
> The IPA objects currently may use gnulib replacement apis, which is

> wrong: gnulib is not linked into the produced dso and it cannot be

> because it is not built with -fPIC -fvisibility=hidden.

> 

> The gnulib replacement detection is broken under cross compilation:

> for targets other than *-gnu*, replacements are enabled that depend

> on execution time detection. This causes unnecessary build failure

> when the target has proper support for the replaced api.

> 

> This fix tries to undo the replacements, which is tricky because the

> gnulib headers are still used for various compile time fixups and

> there is no simple knob in gnulib to only turn the replacements off.

> 

> Without this workaround gdb fails to cross build to non-gnu targets:

> 

>   ld: tracepoint-ipa.o: in function `gdb_agent_helper_thread(void*)':

>   gdb/gdbserver/tracepoint.c:7221: undefined reference to `rpl_strerror'

>   ...

>   Makefile:434: recipe for target 'libinproctrace.so' failed

> 

> gdb/gdbserver/ChangeLog:

> 

> 2018-12-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>

> 

> 	PR gdb/23985

> 	* Makefile.in (IPAGENT_CFLAGS): Add UNDO_GNULIB_CFLAGS.

> 	(UNDO_GNULIB_CFLAGS): Undo gnulib replacements.

> 


ping.

shall i try to remove strerror usage from the code instead?
(i think that's a more intrusive change, but less hackish)
  
Szabolcs Nagy Jan. 30, 2019, 11 a.m. UTC | #2
On 09/01/2019 14:51, Szabolcs Nagy wrote:
> On 14/12/2018 18:03, Szabolcs Nagy wrote:

>> The IPA objects currently may use gnulib replacement apis, which is

>> wrong: gnulib is not linked into the produced dso and it cannot be

>> because it is not built with -fPIC -fvisibility=hidden.

>>

>> The gnulib replacement detection is broken under cross compilation:

>> for targets other than *-gnu*, replacements are enabled that depend

>> on execution time detection. This causes unnecessary build failure

>> when the target has proper support for the replaced api.

>>

>> This fix tries to undo the replacements, which is tricky because the

>> gnulib headers are still used for various compile time fixups and

>> there is no simple knob in gnulib to only turn the replacements off.

>>

>> Without this workaround gdb fails to cross build to non-gnu targets:

>>

>>   ld: tracepoint-ipa.o: in function `gdb_agent_helper_thread(void*)':

>>   gdb/gdbserver/tracepoint.c:7221: undefined reference to `rpl_strerror'

>>   ...

>>   Makefile:434: recipe for target 'libinproctrace.so' failed

>>

>> gdb/gdbserver/ChangeLog:

>>

>> 2018-12-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>

>>

>> 	PR gdb/23985

>> 	* Makefile.in (IPAGENT_CFLAGS): Add UNDO_GNULIB_CFLAGS.

>> 	(UNDO_GNULIB_CFLAGS): Undo gnulib replacements.

>>

> 

> ping.

> 

> shall i try to remove strerror usage from the code instead?

> (i think that's a more intrusive change, but less hackish)

> 


ping2.
  
Pedro Alves Jan. 30, 2019, 5:49 p.m. UTC | #3
OK.

Thanks,
Pedro Alves
On 12/14/2018 06:03 PM, Szabolcs Nagy wrote:
> The IPA objects currently may use gnulib replacement apis, which is
> wrong: gnulib is not linked into the produced dso and it cannot be
> because it is not built with -fPIC -fvisibility=hidden.
> 
> The gnulib replacement detection is broken under cross compilation:
> for targets other than *-gnu*, replacements are enabled that depend
> on execution time detection. This causes unnecessary build failure
> when the target has proper support for the replaced api.
> 
> This fix tries to undo the replacements, which is tricky because the
> gnulib headers are still used for various compile time fixups and
> there is no simple knob in gnulib to only turn the replacements off.
> 
> Without this workaround gdb fails to cross build to non-gnu targets:
> 
>   ld: tracepoint-ipa.o: in function `gdb_agent_helper_thread(void*)':
>   gdb/gdbserver/tracepoint.c:7221: undefined reference to `rpl_strerror'
>   ...
>   Makefile:434: recipe for target 'libinproctrace.so' failed
> 
> gdb/gdbserver/ChangeLog:
> 
> 2018-12-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>
> 
> 	PR gdb/23985
> 	* Makefile.in (IPAGENT_CFLAGS): Add UNDO_GNULIB_CFLAGS.
> 	(UNDO_GNULIB_CFLAGS): Undo gnulib replacements.
>
  

Patch

diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index dfefff9155..b4eb6ca0fb 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -544,9 +544,15 @@  regdat_sh = $(srcdir)/../regformats/regdat.sh
 
 UST_CFLAGS = $(ustinc) -DCONFIG_UST_GDB_INTEGRATION
 
+# Undo gnulib replacements for the IPA shared library build.
+# The gnulib headers are still needed, but gnulib is not linked
+# into the IPA lib so replacement apis don't work.
+UNDO_GNULIB_CFLAGS = -Drpl_strerror=strerror
+
 # Note, we only build the IPA if -fvisibility=hidden is supported in
 # the first place.
 IPAGENT_CFLAGS = $(INTERNAL_CFLAGS) $(UST_CFLAGS) \
+	$(UNDO_GNULIB_CFLAGS) \
 	-fPIC -DIN_PROCESS_AGENT \
 	-fvisibility=hidden