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: unassignedb...@nondot.org
          Reporter: elevi...@accesssoftek.com
                CC: alexander.v.shaposhni...@gmail.com,
                    jake.h.ehrl...@gmail.com,
                    jh7370.2...@my.bristol.ac.uk,
                    llvm-bugs@lists.llvm.org, ruppre...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to