bug#22430: Relocation error with libstdbuf.so on Solaris SPARC with Stud
From:
Rich Burridge
Subject:
bug#22430: Relocation error with libstdbuf.so on Solaris SPARC with Studio compilation.
Date:
Fri, 22 Jan 2016 02:28:26 -0800
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
Hi,
We've noticed an interesting problem recently with the version of stdbuf
(really libstdbuf.so) from coreutils version 8.24 on SPARC in Solaris 12.
If you do something like:
$ stdbuf -oL echo
it generates:
ld.so.1: echo: fatal: relocation error: file /usr/lib/64/libstdbuf.so:
symbol
program_name: referenced symbol not found
Killed
but that same command works just fine for stdbuf and libstdbuf.so from
8.24 in Solaris 12 on x86.
There's a similar problem for the 32-bit version as well. I'll use that
to describe what's going on.
I took the command we use to compile 32-bit libstdbuf.c on SPARC:
and adjusted that to use "-E" instead of "-c" and reran it to generate a
self-contained lsb.c source file (attached).
I then compiled/linked that on SPARC and x86 (using the commands that are
generated by our Userland build environment) and noticed the following
differences:
"src/libstdbuf.c", line 97: warning: shift count negative or too big: << 63
$ elfdump lsb.so | grep program_name
[1] 0 0x4 OBJT GLOB D 0 UNDEF program_name
[42] 0 0x4 OBJT GLOB D 0 UNDEF program_name
2 [1] program_name
[1] 0x1177c 0 R_SPARC_GLOB_DAT program_name
[12] R_SPARC_GLOB_DAT 0x1177c 0 0 .got program_name
$
Now you can see from lsb.c that the code includes:
extern const char *program_name;
...
static inline void
emit_try_help (void)
{
fprintf ( ( & __iob [ 2 ] ), gettext ( "Try '%s --help' for more
information.\n" ), program_name);
}
It looks like the Studio compiler for x86 is nicely optimizing the
emit_try_help() away as it's not being used, but the SPARC version of
the Studio compiler isn't, and is causing the problem.
(Note that this isn't a problem with GNU compiling/linking on Solaris
for both
x86 and SPARC).
Now I can "fix" this by adding progname.o (where the program_name variable
is defined) to libstdbuf.so as it's being linked.