Note: This bug is displayed in read-only format because
the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
DescriptionEdjunior Barbosa Machado
2019-03-28 12:37:16 UTC
Description of problem:
When a PIC shared library that has the main() function is linked against a non-PIC .o file to form a non-PIE executable using gold linker, it generates an executable which segfaults on runtime:
# cat > main.c
#include <stdio.h>
extern int foo(int, int);
int main()
{
printf("%d\n", foo(1, 3));
return 0;
}
# cat > foo.c
int __attribute__ ((noinline)) foo(int x, int y)
{
return x & y;
}
# gcc -o main.o -fPIC -c main.c
# gcc -shared -o libmain.so main.o
# gcc -o foo.o -c foo.c
# gcc -fuse-ld=gold -o a.out -lmain -L$PWD -Wl,-v,-rpath=$PWD foo.o
collect2 version 8.2.1 20180905 (Red Hat 8.2.1-3)
/usr/bin/ld.gold -plugin /usr/libexec/gcc/aarch64-redhat-linux/8/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/cc22QhU0.res -plugin-opt=-pass-throug
h=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -dynamic-linker
/lib/ld-linux-aarch64.so.1 -X -EL -maarch64linux -o a.out /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crt1.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crti.o /usr/lib/gcc/aarch64-redhat-linux
/8/crtbegin.o -L/root/test -L/usr/lib/gcc/aarch64-redhat-linux/8 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../.. -lmain -v
-rpath=/root/test foo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/aarch64-redhat-linux/8/crtend.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crt
n.o
GNU gold (version 2.30-49.el8) 1.15
# ./a.out
Segmentation fault (core dumped)
And it is not reproducible when using ld.bfd:
# gcc -fuse-ld=bfd -o a.out -lmain -L$PWD -Wl,-v,-rpath=$PWD foo.o
collect2 version 8.2.1 20180905 (Red Hat 8.2.1-3)
/usr/bin/ld.bfd -plugin /usr/libexec/gcc/aarch64-redhat-linux/8/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/ccfDVReh.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -dynamic-linker /lib/ld-linux-aarch64.so.1 -X -EL -maarch64linux -o a.out /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crt1.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crti.o /usr/lib/gcc/aarch64-redhat-linux/8/crtbegin.o -L/root/test -L/usr/lib/gcc/aarch64-redhat-linux/8 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../.. -lmain -v -rpath=/root/test foo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/aarch64-redhat-linux/8/crtend.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crtn.o
GNU ld version 2.30-49.el8
# ./a.out
1
This issue currently affects rhel8 aarch64 golang testsuite, as reported on bug #1658418. It was not reproducible on other arches apart from aarch64.
This bug was originally reported as:
https://sourceware.org/bugzilla/show_bug.cgi?id=23870
And it was already fixed upstream with:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=patch;h=7ae39e2d406dbec568c5ffd462119037b994fdf9
Version-Release number of selected component (if applicable):
binutils-2.30-49.el8.x86_64
Comment 1Edjunior Barbosa Machado
2019-03-28 12:41:25 UTC
I backported PR gold/23870 patch against binutils-2.30-49.el8 and verified that it does fixes the aforementioned failures, including the ones from golang testsuite on aarch64.
FWIW, the scratch build with the patch is available at https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20754412
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
https://access.redhat.com/errata/RHBA-2019:3514
Description of problem: When a PIC shared library that has the main() function is linked against a non-PIC .o file to form a non-PIE executable using gold linker, it generates an executable which segfaults on runtime: # cat > main.c #include <stdio.h> extern int foo(int, int); int main() { printf("%d\n", foo(1, 3)); return 0; } # cat > foo.c int __attribute__ ((noinline)) foo(int x, int y) { return x & y; } # gcc -o main.o -fPIC -c main.c # gcc -shared -o libmain.so main.o # gcc -o foo.o -c foo.c # gcc -fuse-ld=gold -o a.out -lmain -L$PWD -Wl,-v,-rpath=$PWD foo.o collect2 version 8.2.1 20180905 (Red Hat 8.2.1-3) /usr/bin/ld.gold -plugin /usr/libexec/gcc/aarch64-redhat-linux/8/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/cc22QhU0.res -plugin-opt=-pass-throug h=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -dynamic-linker /lib/ld-linux-aarch64.so.1 -X -EL -maarch64linux -o a.out /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crt1.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crti.o /usr/lib/gcc/aarch64-redhat-linux /8/crtbegin.o -L/root/test -L/usr/lib/gcc/aarch64-redhat-linux/8 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../.. -lmain -v -rpath=/root/test foo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/aarch64-redhat-linux/8/crtend.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crt n.o GNU gold (version 2.30-49.el8) 1.15 # ./a.out Segmentation fault (core dumped) And it is not reproducible when using ld.bfd: # gcc -fuse-ld=bfd -o a.out -lmain -L$PWD -Wl,-v,-rpath=$PWD foo.o collect2 version 8.2.1 20180905 (Red Hat 8.2.1-3) /usr/bin/ld.bfd -plugin /usr/libexec/gcc/aarch64-redhat-linux/8/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/ccfDVReh.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -dynamic-linker /lib/ld-linux-aarch64.so.1 -X -EL -maarch64linux -o a.out /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crt1.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crti.o /usr/lib/gcc/aarch64-redhat-linux/8/crtbegin.o -L/root/test -L/usr/lib/gcc/aarch64-redhat-linux/8 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/aarch64-redhat-linux/8/../../.. -lmain -v -rpath=/root/test foo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/aarch64-redhat-linux/8/crtend.o /usr/lib/gcc/aarch64-redhat-linux/8/../../../../lib64/crtn.o GNU ld version 2.30-49.el8 # ./a.out 1 This issue currently affects rhel8 aarch64 golang testsuite, as reported on bug #1658418. It was not reproducible on other arches apart from aarch64. This bug was originally reported as: https://sourceware.org/bugzilla/show_bug.cgi?id=23870 And it was already fixed upstream with: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=patch;h=7ae39e2d406dbec568c5ffd462119037b994fdf9 Version-Release number of selected component (if applicable): binutils-2.30-49.el8.x86_64