Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Define symbols "_end" and "end" if referenced.
These symbols are expected to point to the end of the data segment. Implements http://llvm.org/pr25528. Differential Revision: http://reviews.llvm.org/D14833 llvm-svn: 253637
- Loading branch information
Igor Kudrin
committed
Nov 20, 2015
1 parent
dcb5653
commit b044af5
Showing
7 changed files
with
159 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Should preserve the value of the "end" symbol if it is defined. | ||
// REQUIRES: x86 | ||
|
||
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o | ||
// RUN: ld.lld %t.o -o %t | ||
// RUN: llvm-nm %t | FileCheck %s | ||
|
||
// CHECK: 0000000000000005 A end | ||
|
||
.global _start,end | ||
end = 5 | ||
.text | ||
_start: | ||
nop | ||
.bss | ||
.space 6 |
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,29 @@ | ||
// Should set the value of the "end" symbol if it is undefined. | ||
// REQUIRES: x86 | ||
|
||
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o | ||
// RUN: ld.lld %t.o -o %t | ||
// RUN: llvm-readobj -sections -symbols %t | FileCheck %s | ||
|
||
// CHECK: Sections [ | ||
// CHECK: Name: .bss | ||
// CHECK-NEXT: Type: | ||
// CHECK-NEXT: Flags [ | ||
// CHECK-NEXT: SHF_ALLOC | ||
// CHECK-NEXT: SHF_WRITE | ||
// CHECK-NEXT: ] | ||
// CHECK-NEXT: Address: 0x12000 | ||
// CHECK-NEXT: Offset: | ||
// CHECK-NEXT: Size: 6 | ||
// CHECK: ] | ||
// CHECK: Symbols [ | ||
// CHECK: Name: end | ||
// CHECK-NEXT: Value: 0x12006 | ||
// CHECK: ] | ||
|
||
.global _start,end | ||
.text | ||
_start: | ||
nop | ||
.bss | ||
.space 6 |
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,79 @@ | ||
// Should set the value of the "_end" symbol to the end of the data segment. | ||
// REQUIRES: x86 | ||
|
||
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o | ||
|
||
// By default, the .bss section is the latest section of the data segment. | ||
// RUN: ld.lld %t.o -o %t | ||
// RUN: llvm-readobj -sections -symbols %t | FileCheck %s --check-prefix=DEFAULT | ||
|
||
// DEFAULT: Sections [ | ||
// DEFAULT: Name: .bss | ||
// DEFAULT-NEXT: Type: | ||
// DEFAULT-NEXT: Flags [ | ||
// DEFAULT-NEXT: SHF_ALLOC | ||
// DEFAULT-NEXT: SHF_WRITE | ||
// DEFAULT-NEXT: ] | ||
// DEFAULT-NEXT: Address: 0x12002 | ||
// DEFAULT-NEXT: Offset: | ||
// DEFAULT-NEXT: Size: 6 | ||
// DEFAULT: ] | ||
// DEFAULT: Symbols [ | ||
// DEFAULT: Name: _end | ||
// DEFAULT-NEXT: Value: 0x12008 | ||
// DEFAULT: ] | ||
|
||
// If there is no .bss section, "_end" should point to the end of the .data section. | ||
// RUN: echo "SECTIONS { \ | ||
// RUN: /DISCARD/ : { *(.bss) } }" > %t.script | ||
// RUN: ld.lld %t.o --script %t.script -o %t | ||
// RUN: llvm-readobj -sections -symbols %t | FileCheck %s --check-prefix=NOBSS | ||
|
||
// NOBSS: Sections [ | ||
// NOBSS: Name: .data | ||
// NOBSS-NEXT: Type: | ||
// NOBSS-NEXT: Flags [ | ||
// NOBSS-NEXT: SHF_ALLOC | ||
// NOBSS-NEXT: SHF_WRITE | ||
// NOBSS-NEXT: ] | ||
// NOBSS-NEXT: Address: 0x12000 | ||
// NOBSS-NEXT: Offset: | ||
// NOBSS-NEXT: Size: 2 | ||
// NOBSS: ] | ||
// NOBSS: Symbols [ | ||
// NOBSS: Name: _end | ||
// NOBSS-NEXT: Value: 0x12002 | ||
// NOBSS: ] | ||
|
||
// If the layout of the sections is changed, "_end" should point to the end of allocated address space. | ||
// RUN: echo "SECTIONS { \ | ||
// RUN: .bss : { *(.bss) } \ | ||
// RUN: .data : { *(.data) } \ | ||
// RUN: .text : { *(.text) } }" > %t.script | ||
// RUN: ld.lld %t.o --script %t.script -o %t | ||
// RUN: llvm-readobj -sections -symbols %t | FileCheck %s --check-prefix=TEXTATEND | ||
|
||
// TEXTATEND: Sections [ | ||
// TEXTATEND: Name: .text | ||
// TEXTATEND-NEXT: Type: | ||
// TEXTATEND-NEXT: Flags [ | ||
// TEXTATEND-NEXT: SHF_ALLOC | ||
// TEXTATEND-NEXT: SHF_EXECINSTR | ||
// TEXTATEND-NEXT: ] | ||
// TEXTATEND-NEXT: Address: 0x12000 | ||
// TEXTATEND-NEXT: Offset: | ||
// TEXTATEND-NEXT: Size: 1 | ||
// TEXTATEND: ] | ||
// TEXTATEND: Symbols [ | ||
// TEXTATEND: Name: _end | ||
// TEXTATEND-NEXT: Value: 0x12001 | ||
// TEXTATEND: ] | ||
|
||
.global _start,_end | ||
.text | ||
_start: | ||
nop | ||
.data | ||
.word 1 | ||
.bss | ||
.space 6 |
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