xref: /llvm-project/lld/test/ELF/linkerscript/symbol-assign-type.s (revision 9670029b6b302c75bb373fb1814f4e02790c4da8)
1# REQUIRES: x86
2## Keep st_type for simple assignment (`alias = aliasee`). This property is
3## desired on some targets, where symbol types can affect relocation processing
4## (e.g. Thumb interworking). However, the st_size field should not be retained
5## because some tools use st_size=0 as a heuristic to detect aliases. With any
6## operation, it can be argued that the new symbol may not be of the same type,
7## so reset st_type to STT_NOTYPE.
8
9## NOTE: GNU ld retains st_type for many operations.
10
11# RUN: split-file %s %t
12# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/main.s -o %t.o
13# RUN: ld.lld -T %t/a.lds %t.o -o %t1
14# RUN: llvm-readelf -s %t1 | FileCheck %s
15
16# CHECK:      Size Type   Bind   Vis     Ndx Name
17# CHECK:         1 FUNC   GLOBAL DEFAULT   1 _start
18# CHECK:         0 FUNC   GLOBAL DEFAULT   1 retain1
19# CHECK-NEXT:    0 FUNC   GLOBAL DEFAULT   1 retain2
20# CHECK-NEXT:    0 NOTYPE GLOBAL DEFAULT   1 drop1
21# CHECK-NEXT:    0 NOTYPE GLOBAL DEFAULT ABS drop2
22# CHECK-NEXT:    0 NOTYPE GLOBAL DEFAULT ABS drop3
23
24# RUN: ld.lld --defsym 'retain=_start' --defsym 'drop=_start+0' %t.o -o %t2
25# RUN: llvm-readelf -s %t2 | FileCheck %s --check-prefix=DEFSYM
26
27# DEFSYM:        0 FUNC   GLOBAL DEFAULT   1 retain
28# DEFSYM-NEXT:   0 NOTYPE GLOBAL DEFAULT   1 drop
29
30#--- a.lds
31retain1 = _start;
32retain2 = 1 ? _start : 0;
33
34## Reset to STT_NOTYPE if any operation is performed,
35## even if the operation is an identity function.
36drop1 = _start + 0;
37drop2 = 0 ? _start : 1;
38drop3 = -_start;
39
40#--- main.s
41.globl _start
42.type _start, @function
43_start:
44  ret
45.size _start, 1
46