2017-07-03 23:49:25 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
|
|
|
|
# RUN: echo "SECTIONS { \
|
2018-02-07 17:11:07 +08:00
|
|
|
# RUN: .got : { *(.got) *(.got) } \
|
2017-07-03 23:49:25 +08:00
|
|
|
# RUN: .plt : { *(.plt) } \
|
|
|
|
# RUN: .text : { *(.text) } \
|
|
|
|
# RUN: }" > %t.script
|
|
|
|
# RUN: ld.lld -shared -o %t.so --script %t.script %t.o
|
|
|
|
|
2018-11-06 04:39:06 +08:00
|
|
|
# RUN: llvm-readelf -S %t.so | FileCheck %s
|
2017-07-03 23:49:25 +08:00
|
|
|
# CHECK-NOT: .got
|
|
|
|
# CHECK-NOT: .plt
|
2018-05-16 01:02:35 +08:00
|
|
|
# CHECK: .dynsym
|
2018-06-27 01:04:47 +08:00
|
|
|
# CHECK: .text
|
2017-07-03 23:49:25 +08:00
|
|
|
|
[ELF] Reset OutputSection size prior to processing linker script commands
The size of an OutputSection is calculated early, to aid handling of compressed
debug sections. However, subsequent to this point, unused synthetic sections are
removed. In the event that an OutputSection, from which such an InputSection is
removed, is still required (e.g. because it has a symbol assignment), and no longer
has any InputSections, dot assignments, or BYTE()-family directives, the size
member is never updated when processing the commands. If the removed InputSection
had a non-zero size (such as a .got.plt section), the section ends up with the
wrong size in the output.
The fix is to reset the OutputSection size prior to processing the linker script
commands relating to that OutputSection. This ensures that the size is correct even
in the above situation.
Additionally, to reduce the risk of developers misusing OutputSection Size and
InputSection OutSecOff, they are set to simply the number of InputSections in an
OutputSection, and the corresponding index respectively. We cannot completely
stop using them, due to SHF_LINK_ORDER sections requiring them.
Compressed debug sections also require the full size. This is now calculated in
maybeCompress for these kinds of sections.
Reviewers: ruiu, rafael
Differential Revision: https://reviews.llvm.org/D38361
llvm-svn: 320472
2017-12-12 19:51:13 +08:00
|
|
|
# Test that the size of a removed unused synthetic input section is not added
|
|
|
|
# to the output section size. Adding a symbol assignment prevents removal of
|
|
|
|
# the output section, but does not cause the section size to be recomputed.
|
|
|
|
# RUN: echo "SECTIONS { \
|
|
|
|
# RUN: .got.plt : { a_sym = .; *(.got.plt) } \
|
|
|
|
# RUN: }" > %t2.script
|
|
|
|
# RUN: ld.lld -shared -o %t2.so --script %t2.script %t.o
|
2020-03-16 08:47:44 +08:00
|
|
|
# RUN: llvm-objdump --section-headers %t2.so | FileCheck %s --check-prefix=CHECK2
|
[ELF] Reset OutputSection size prior to processing linker script commands
The size of an OutputSection is calculated early, to aid handling of compressed
debug sections. However, subsequent to this point, unused synthetic sections are
removed. In the event that an OutputSection, from which such an InputSection is
removed, is still required (e.g. because it has a symbol assignment), and no longer
has any InputSections, dot assignments, or BYTE()-family directives, the size
member is never updated when processing the commands. If the removed InputSection
had a non-zero size (such as a .got.plt section), the section ends up with the
wrong size in the output.
The fix is to reset the OutputSection size prior to processing the linker script
commands relating to that OutputSection. This ensures that the size is correct even
in the above situation.
Additionally, to reduce the risk of developers misusing OutputSection Size and
InputSection OutSecOff, they are set to simply the number of InputSections in an
OutputSection, and the corresponding index respectively. We cannot completely
stop using them, due to SHF_LINK_ORDER sections requiring them.
Compressed debug sections also require the full size. This is now calculated in
maybeCompress for these kinds of sections.
Reviewers: ruiu, rafael
Differential Revision: https://reviews.llvm.org/D38361
llvm-svn: 320472
2017-12-12 19:51:13 +08:00
|
|
|
# CHECK2: .got.plt 00000000
|
|
|
|
|
2017-07-03 23:49:25 +08:00
|
|
|
.global _start
|
|
|
|
_start:
|
|
|
|
nop
|