[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / linkerscript / symbol-assign-type.s
blob3f7dfd6faad4719b32ae3377941c7807e4b0659e
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.
9 ## NOTE: GNU ld retains st_type for many operations.
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
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
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
27 # DEFSYM: 0 FUNC GLOBAL DEFAULT 1 retain
28 # DEFSYM-NEXT: 0 NOTYPE GLOBAL DEFAULT 1 drop
30 #--- a.lds
31 retain1 = _start;
32 retain2 = 1 ? _start : 0;
34 ## Reset to STT_NOTYPE if any operation is performed,
35 ## even if the operation is an identity function.
36 drop1 = _start + 0;
37 drop2 = 0 ? _start : 1;
38 drop3 = -_start;
40 #--- main.s
41 .globl _start
42 .type _start, @function
43 _start:
44 ret
45 .size _start, 1