https://bugs.llvm.org/show_bug.cgi?id=42052
Bug ID: 42052
Summary: Bad interaction with llvm-objcopy + gold
Product: tools
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: llvm-objcopy/strip
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected],
[email protected],
[email protected],
[email protected], [email protected]
Before llvm-objcopy writes out, it sorts sections by offset:
https://github.com/llvm/llvm-project/blob/master/llvm/tools/llvm-objcopy/ELF/Object.cpp#L1480
However, gold expects that the index of section groups is smaller than the
indices of sections that it contains:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gold/object.cc;h=689448f50c8a784d1142032875203ffc1d28661f;hb=HEAD#l1090
This does seem to be required by the ELF spec: "The section header table entry
for a group section must appear in the section header table before the entries
for any of the sections that are members of the group." Only gold complains
though -- ld and lld work fine (accepting invalid ELF, I guess).
Because llvm-objcopy only looks at the offsets, if an SHT_GROUP section has a
greater offset than the sections it contains (while still having the section
header come first), llvm-objcopy can rearrange it into an invalid ordering.
Small-ish repro:
$ cat repro.cc
#include <string>
std::string foo(std::string x) { return x + x; }
int main() {
foo("x");
return 0;
}
# Normal link w/ gold (passes)
$ clang++ -c group.cc -o /tmp/group.o
$ clang++ -fuse-ld=gold -o /tmp/group /tmp/group.o
# Invoke GNU objcopy & link w/ gold (passes)
$ objcopy /tmp/group.o /tmp/group.gnu.o
$ clang++ -fuse-ld=gold -o /tmp/group /tmp/group.gnu.o
# Invoke llvm-objcopy & link w/ gold (fails)
$ llvm-objcopy /tmp/group.o /tmp/group.llvm.o
$ clang++ -fuse-ld=gold -o /tmp/group /tmp/group.llvm.o
/usr/bin/ld.gold: error: /tmp/group.llvm.o: invalid section group 8 refers to
earlier section 2
The simplest thing is probably to change that comparator to always put
SHT_GROUP first, which I believe is effectively what GNU objcopy does.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs