ada: Fix musl build on Linux

Message ID Y+Nu6les4SuFnrsB@guest.guest
State Accepted
Headers
Series ada: Fix musl build on Linux |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

宋冬生 Feb. 8, 2023, 9:44 a.m. UTC
  The commit "ada: Add PIE support to backtraces on Linux" [1] use
_r_debug under Linux unconditionally. It is incorrect since musl[2]
libc not defined _r_debug like glibc [3]:

extern struct r_debug _r_debug;

As far as I know, only glibc and uClibc [4] define the global variable
_r_debug. 


[1] https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=f2b30a724e6bf7ff8e591b176967d596cee7648e;hp=83e8d37fe39d7c1afce19b61bbc2dd828fa37c6f
[2] https://git.musl-libc.org/cgit/musl/tree/include/link.h#n39
[3] https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/link.h;h=3b5954d9818e8ea9f35638c55961f861f6ae6057;hb=HEAD#l66
[4] https://git.uclibc.org/uClibc/tree/include/link.h#n71

OK? Bootstrapped and tested on aarch64-linux-(gnu|musl),
riscv64-linux-(gnu|musl) and x86_64-linux-(gnu|musl) with no regressions.


gcc/ada/

* adaint.c [Linux]: Include <features.h>.
(__gnat_get_executable_load_address) [Linux]: Enable only for glibc & uClibc
on Linux.


 gcc/ada/adaint.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Arnaud Charlet Feb. 8, 2023, 11:12 a.m. UTC | #1
> The commit "ada: Add PIE support to backtraces on Linux" [1] use
> _r_debug under Linux unconditionally. It is incorrect since musl[2]
> libc not defined _r_debug like glibc [3]:
> 
> extern struct r_debug _r_debug;
> 
> As far as I know, only glibc and uClibc [4] define the global variable
> _r_debug. 
> 
> 
> [1] https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=f2b30a724e6bf7ff8e591b176967d596cee7648e;hp=83e8d37fe39d7c1afce19b61bbc2dd828fa37c6f
> [2] https://git.musl-libc.org/cgit/musl/tree/include/link.h#n39
> [3] https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/link.h;h=3b5954d9818e8ea9f35638c55961f861f6ae6057;hb=HEAD#l66
> [4] https://git.uclibc.org/uClibc/tree/include/link.h#n71
> 
> OK? Bootstrapped and tested on aarch64-linux-(gnu|musl),
> riscv64-linux-(gnu|musl) and x86_64-linux-(gnu|musl) with no regressions.

OK, thanks,

> gcc/ada/
> 
> * adaint.c [Linux]: Include <features.h>.
> (__gnat_get_executable_load_address) [Linux]: Enable only for glibc & uClibc
> on Linux.
  

Patch

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index 1c23d1584..852209416 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -3526,6 +3526,7 @@  __gnat_cpu_set (int cpu, size_t count ATTRIBUTE_UNUSED, cpu_set_t *set)
 #if defined (__APPLE__)
 #include <mach-o/dyld.h>
 #elif defined (__linux__)
+#include <features.h>
 #include <link.h>
 #endif
 
@@ -3535,7 +3536,7 @@  __gnat_get_executable_load_address (void)
 #if defined (__APPLE__)
   return _dyld_get_image_header (0);
 
-#elif defined (__linux__)
+#elif defined (__linux__) && (defined (__GLIBC__) || defined (__UCLIBC__))
   struct link_map *map = _r_debug.r_map;
   return (const void *)map->l_addr;