[PATCH] [RFC] Building for SuperH fails with gcc5/6

Alexey Neyman stilor@att.net
Thu Jan 26 07:03:00 GMT 2017


Hi,

Build glibc for sh4-unknown-linux-gnu currently fails if one's using 
GCC5/6: in dl-conflict.c, the elf_machine_rela() function is called with 
NULL as its 3rd argument, sym. The implementation of that function in 
sysdeps/sh/dl-machine.h dereferences that pointer:

const Elf32_Sym *const refsym = sym;
...
if (map == &GL(dl_rtld_map))
   value -= map->l_addr + refsym->st_value + reloc->r_addend;

GCC discovers a null pointer dereference, and in accordance with 
-fdelete-null-pointer-checks (which is enabled in -O2) replaces this 
code with a trap - which, as SH does not implement a trap pattern in 
GCC, evaluates to an abort() call. This abort() call pulls many more 
objects from libc_nonshared.a, eventually resulting in link failure due 
to multiple definitions for a number of symbols.

As far as I see, the conditional before this code is always false in 
rtld: _dl_resolve_conflicts() is called with main_map as the first 
argument, not GL(_dl_rtld_map), but since that call is in yet another 
compilation unit, GCC does not know about it. Patch that wraps this 
conditional into !defined RESOLVE_CONFLICT_FIND_MAP attached.

However, I thought the abort() call may be also inserted by GCC on other 
architectures that do not implement the trap pattern, so it may make 
sense to provide a dummy abort() in rtld that does not pull any other 
dependencies. An alternative patch for this approach also attached.

And, of course, it is also possible to just add 
-fno-delete-null-pointer-checks to the compiler flags for dl-conflict.c 
on SH, even though it would unnecessarily pessimize the code.

Comments?

Regards,
Alexey.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Provide-a-minimal-abort-stub-for-rtld.patch
Type: text/x-patch
Size: 2016 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20170126/c0f9ac95/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-sh-conditional-is-false-in-dl-conflict.c.patch
Type: text/x-patch
Size: 959 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20170126/c0f9ac95/attachment-0001.bin>


More information about the Libc-alpha mailing list