Bug 2119383 - binutils not working correctly with "clang -flto"
Summary: binutils not working correctly with "clang -flto"
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: binutils
Version: 7.9
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Nick Clifton
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On: 2119380 2120959
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-08-18 13:45 UTC by Jesus Checa
Modified: 2023-07-18 14:16 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Known Issue
Doc Text:
Cause: When the LLVM compiler generates object files intended for secondary compilation via LTO it uses an internal file format rather than ELF. Consequence: Tools which expect ELF format input files, eg the linker, nm, readelf, etc, will fail to recognise LLVM bitcode files. Workaround (if any): For most tools adding the command line option --plugin=LLVMgold.so will solve the problem. The readelf program does not support this option however, so an alternative is to use the llvm-bcanalyzer program. Result: Using the workarounds resolves the problem.
Clone Of: 2119380
Environment:
Last Closed: 2022-08-18 16:05:32 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-131417 0 None None None 2022-08-18 13:51:17 UTC

Description Jesus Checa 2022-08-18 13:45:49 UTC
+++ This bug was initially created as a clone of Bug #2119380 +++

Description of problem:
binutils are not able to correctly read objects and binaries compiled with "clang -flto".

I tested this in RHEL-9.0 and Fedora 34+. In those environments the output is as expected.

This is reproducible in every supported arch.

How reproducible:
100%

Steps to Reproduce:
1. echo "void lto_function(){}" | clang -flto -O2 -c -x c -o foo.o -
2. nm foo.o
3. ar crs foo.a foo.o
4. readelf -c foo.a

Actual results:
[root@hpe-apollo-cn99xx-14-vm-25 ~]# echo "void lto_function(){}" | clang -flto -O2 -c -x c -o foo.o -
[root@hpe-apollo-cn99xx-14-vm-25 ~]# nm foo.o
nm: foo.o: file format not recognized
[root@hpe-apollo-cn99xx-14-vm-25 ~]# ar crs foo.a foo.o
[root@hpe-apollo-cn99xx-14-vm-25 ~]# readelf -c foo.a
foo.a has no archive index
readelf: foo.a: Error: foo.a: unable to dump the index as none was found

Expected results:
$  echo "void lto_function(){}" | clang -flto -O2 -c -x c -o foo.o -
$ nm foo.o
00000000 T lto_function
$ ranlib foo.a foo.o
ranlib: foo.o: file format not recognized
$ ar crs foo.a foo.o
$ readelf -c foo.a
Index of archive foo.a: (1 entries, 0xe bytes in the symbol table)
Contents of binary foo.a(foo.o) at offset 0x5a
        lto_function

Comment 3 Nick Clifton 2022-08-18 16:05:32 UTC
Workarounds are available, so closing this BZ.


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