[llvm-bugs] [Bug 41461] New: llvm-objcopy outputs broken ELF image on large object files built with -ffunction-sections
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Apr 11 01:32:05 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41461
Bug ID: 41461
Summary: llvm-objcopy outputs broken ELF image on large object
files built with -ffunction-sections
Product: tools
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: release blocker
Priority: P
Component: llvm-objcopy/strip
Assignee: unassignedbugs at nondot.org
Reporter: eleviant at accesssoftek.com
CC: alexander.v.shaposhnikov at gmail.com,
jake.h.ehrlich at gmail.com,
jh7370.2008 at my.bristol.ac.uk,
llvm-bugs at lists.llvm.org, rupprecht at google.com
Steps to reproduce:
1. Generate source file with this bash script:
#!/bin/bash
echo "extern int baz();"
count=0
while [ $count -le 65280 ]; do
echo "int fun_$count() { return baz(); }"
((count++))
done
This will generate C source file with large number of functions (65281),
forcing some of symbol section indexes to become SHN_XINDEX.
2. Compile source
clang <file> -c -ffunction-sections -o output.o
This will generate object file with each of 'fun_[0-9]+' residing in it's own
section followed by relocation section '.rela.fun_[0-9]+'. It's important that
sections in output.o are not sorted by offset, so llvm-objcopy will reorder
them in sortSection changing indexes.
3. Run llvm-objcopy
llvm-objcopy output.o output-bad.o
Now the bug can be observed using readelf:
readelf -sW output-bad.o | grep 'fun_65278'
126706: 0000000000000000 13 FUNC GLOBAL DEFAULT UND fun_65278
readelf -sW output-bad.o | grep '65280:'
65280: 0000000000000000 0 SECTION LOCAL DEFAULT UND
====================
Explanation:
The problem lies in .symtab_shndx section being filled too early (in
prepareForLayout) before indexes are assigned to the sections in
layoutSections. Those indexes may not match original indexes because
llvm-objcopy sorts sections by OriginalOffset. This causes symbol section
indexes in result image to not match sections those symbols are defined in
(when section index exceeds SHN_LORESERVE).
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190411/8ca9f3f8/attachment-0001.html>
More information about the llvm-bugs
mailing list