-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Don't output headers into a segment if there's no space for them
Currently, LLD checks whether there's enough space for headers by checking if headers fit below the address of the first allocated section. However, that's always thue if the binary doesn't start at zero which means that LLD always emits a segment for headers, even if no other sections belong to that segment. This is a problem in cases when linker script is being used with a non-zero start address when we don't want to make the headers visible by not leaving enough space for them. This pattern is common in embedded programming but doesn't work in LLD. This patch changes the behavior of LLD in case when linker script is being to match the behavior of BFD ld and gold, which is to only place headers into a segment when they're covered by some output section. Differential Revision: https://reviews.llvm.org/D36256 llvm-svn: 311586
- Loading branch information
Showing
6 changed files
with
54 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# REQUIRES: x86 | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o | ||
# RUN: echo "SECTIONS { . = 0x2000; .text : AT(0x100000) { *(.text) } }" > %t.script | ||
# RUN: ld.lld -o %t --script %t.script %t.o | ||
# RUN: llvm-readobj -l %t | FileCheck %s | ||
|
||
# CHECK: ProgramHeaders [ | ||
# CHECK-NEXT: ProgramHeader { | ||
# CHECK-NEXT: Type: PT_LOAD (0x1) | ||
# CHECK-NEXT: Offset: 0x1000 | ||
# CHECK-NEXT: VirtualAddress: 0x2000 | ||
# CHECK-NEXT: PhysicalAddress: 0x100000 | ||
# CHECK-NEXT: FileSize: 1 | ||
# CHECK-NEXT: MemSize: 1 | ||
# CHECK-NEXT: Flags [ (0x5) | ||
# CHECK-NEXT: PF_R (0x4) | ||
# CHECK-NEXT: PF_X (0x1) | ||
# CHECK-NEXT: ] | ||
# CHECK-NEXT: Alignment: 4096 | ||
# CHECK-NEXT: } | ||
|
||
.section .text | ||
.global _start | ||
|
||
_start: | ||
ret |