xref: /llvm-project/lld/test/ELF/edata-etext.s (revision 330abe8d4386eb0386ae80d969dc3d01ee7d3f48)
1# REQUIRES: x86
2# RUN: rm -rf %t && split-file %s %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t/a.s -o %t/a.o
4# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t/b.s -o %t/b.o
5# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t/c.s -o %t/c.o
6# RUN: ld.lld %t/a.o -o %t/a
7# RUN: llvm-objdump -t --section-headers %t/a | FileCheck %s
8
9## This checks that:
10## 1) Address of _etext is the first location after the last read-only loadable segment.
11## 2) Address of _edata points to the end of the last non SHT_NOBITS section.
12##    That is how gold/bfd do. At the same time specs says: "If the address of _edata is
13##    greater than the address of _etext, the address of _end is same as the address
14##    of _edata." (https://docs.oracle.com/cd/E53394_01/html/E54766/u-etext-3c.html).
15## 3) Address of _end is different from _edata because of 2.
16## 4) Addresses of _edata == edata, _end == end and _etext == etext.
17# CHECK:      Sections:
18# CHECK-NEXT:  Idx Name          Size     VMA              Type
19# CHECK-NEXT:    0               00000000 0000000000000000
20# CHECK-NEXT:    1 .text         00000001 0000000000201158 TEXT
21# CHECK-NEXT:    2 .data         00000002 0000000000202159 DATA
22# CHECK-NEXT:    3 .bss          00000006 000000000020215c BSS
23# CHECK:      SYMBOL TABLE:
24# CHECK-NEXT:  000000000020215b g       .data 0000000000000000 _edata
25# CHECK-NEXT:  0000000000202162 g       .bss  0000000000000000 _end
26# CHECK-NEXT:  0000000000201159 g       .text 0000000000000000 _etext
27# CHECK-NEXT:  0000000000201158 g       .text 0000000000000000 _start
28# CHECK-NEXT:  000000000020215b g       .data 0000000000000000 edata
29# CHECK-NEXT:  0000000000202162 g       .bss  0000000000000000 end
30# CHECK-NEXT:  0000000000201159 g       .text 0000000000000000 etext
31
32# RUN: ld.lld -r %t/a.o -o %t/a.ro
33# RUN: llvm-objdump -t %t/a.ro | FileCheck %s --check-prefix=RELOCATABLE
34# RELOCATABLE:       0000000000000000 *UND* 0000000000000000 _edata
35# RELOCATABLE-NEXT:  0000000000000000 *UND* 0000000000000000 _end
36# RELOCATABLE-NEXT:  0000000000000000 *UND* 0000000000000000 _etext
37
38## If a relocatable object file defines non-reserved identifiers (by C and C++)
39## edata/end/etext, don't redefine them. Note: GNU ld redefines the reserved
40## _edata while we don't for simplicity.
41# RUN: ld.lld %t/b.o -o %t/b
42# RUN: llvm-objdump -t %t/b | FileCheck %s --check-prefix=CHECK2
43# RUN: ld.lld %t/c.o -o %t/c
44# RUN: llvm-objdump -t %t/c | FileCheck %s --check-prefix=CHECK2
45## PROVIDE does not redefine defined symbols, even if COMMON.
46# RUN: ld.lld %t/c.o %t/lds -o %t/c
47# RUN: llvm-objdump -t %t/c | FileCheck %s --check-prefix=CHECK2
48
49# CHECK2:       [[#%x,]] g     O .bss   0000000000000001 _edata
50# CHECK2-NEXT:  [[#%x,]] g     O .bss   0000000000000001 edata
51# CHECK2-NEXT:  [[#%x,]] g     O .bss   0000000000000001 end
52# CHECK2-NEXT:  [[#%x,]] g     O .bss   0000000000000001 etext
53
54#--- a.s
55.global _edata,_end,_etext,_start,edata,end,etext
56.text
57_start:
58  nop
59.data
60  .word 1
61.bss
62  .align 4
63  .space 6
64
65#--- b.s
66.bss
67.macro def x
68  .globl \x
69  .type \x, @object
70  \x: .byte 0
71  .size \x, 1
72.endm
73def _edata
74def edata
75def end
76def etext
77
78#--- c.s
79.comm _edata,1,1
80.comm edata,1,1
81.comm end,1,1
82.comm etext,1,1
83
84#--- lds
85SECTIONS {
86  .text : { *(.text) }
87
88  PROVIDE(etext = .);
89  PROVIDE(edata = .);
90  PROVIDE(end = .);
91}
92