Bug 2106133 - Confusing message when using -r attempting to create a relocatable object from multiple objects
Summary: Confusing message when using -r attempting to create a relocatable object fro...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: gcc
Version: 8.6
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: Marek Polacek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-07-11 20:13 UTC by Paulo Andrade
Modified: 2023-07-18 14:19 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-07-13 17:50:00 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-127428 0 None None None 2022-07-11 20:19:15 UTC

Description Paulo Andrade 2022-07-11 20:13:19 UTC
In C it would be like:

$ gcc hello.c -o hello.o -c
hello.c: In function ‘main’:
hello.c:3:1: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
 printf("hello world!\n");
 ^

$ file hello.o
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

$ gcc hello.o -r 
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status

  But the actual problem user experienced was:

$ gfortran -v -r -o BIG.o a.o b.o c.o ...
Driving: gfortran -v -r -o BIG.o a.o b.o c.o -l gfortran -l m -shared-libgcc
...
OLLECT_GCC_OPTIONS='-v' '-r' '-o' 'BIG.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/8/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/8/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/ccEsZ4ao.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o BIG.o -r /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/8/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/8 -L/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/8/../../.. a.o b.o c.o ... -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/8/crtend.o /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crtn.o
/usr/bin/ld: cannot find -lgfortran
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lquadmath
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status

  The driver should print some error message when '-r' is used like this. As well
as some explanation about the issue.

  The linker is attempting to statically link.

Comment 1 Marek Polacek 2022-07-11 21:14:18 UTC
It seems to me that the problem is rather that in older GCCs -r didn't imply -nostdlib.

So I think the workaround/solution is to use -r -nostdlib.


Note You need to log in before you can comment on or make changes to this bug.