162 lines · plain
1# REQUIRES: x862 3# RUN: rm -rf %t && split-file %s %t && cd %t4# RUN: llvm-mc -n -filetype=obj -triple=x86_64 -o shared.o shared.s5# RUN: ld.lld -shared shared.o -o a.so6# RUN: llvm-mc -n -filetype=obj -triple=x86_64 -o a.o a.s7 8#--- shared.s9.globl test_shared10.section .test_shared,"ax",@progbits11test_shared:12 jmp test_shared13 14#--- a.s15## Simple live section16.globl _start17.section ._start,"ax",@progbits18_start:19 jmp test_simple20 .quad .Lanonymous21 .quad .Lanonymous_within_symbol22 jmp test_shared23 .quad test_local24.size _start, .-_start25 26.globl test_simple27.section .test_simple,"ax",@progbits28test_simple:29 jmp test_simple30 jmp test_from_unsized31 32# RUN: ld.lld a.o a.so --gc-sections --why-live=test_simple | FileCheck %s --check-prefix=SIMPLE33 34# SIMPLE: live symbol: a.o:(test_simple)35# SIMPLE-NEXT: >>> referenced by: a.o:(_start) (entry point)36# SIMPLE-EMPTY:37 38## Live only by being a member of .test_simple39.globl test_incidental40test_incidental:41 jmp test_incidental42 43# RUN: ld.lld a.o a.so --gc-sections --why-live=test_incidental | FileCheck %s --check-prefix=INCIDENTAL44 45# INCIDENTAL: live symbol: a.o:(test_incidental)46# INCIDENTAL-NEXT: >>> in live section: a.o:(.test_simple)47# INCIDENTAL-NEXT: >>> contained live symbol: a.o:(test_simple)48# INCIDENTAL-NEXT: >>> referenced by: a.o:(_start) (entry point)49# INCIDENTAL-EMPTY:50 51## Reached from a reference in section .test_simple directly, since test_simple is an unsized symbol.52.globl test_from_unsized53.section .test_from_unsized,"ax",@progbits54test_from_unsized:55 jmp test_from_unsized56 57# RUN: ld.lld a.o a.so --gc-sections --why-live=test_from_unsized | FileCheck %s --check-prefix=FROM-UNSIZED58 59# FROM-UNSIZED: live symbol: a.o:(test_from_unsized)60# FROM-UNSIZED-NEXT: >>> referenced by: a.o:(.test_simple)61# FROM-UNSIZED-NEXT: >>> contained live symbol: a.o:(test_simple)62# FROM-UNSIZED-NEXT: >>> referenced by: a.o:(_start) (entry point)63# FROM-UNSIZED-EMPTY:64 65## Symbols in dead sections are dead and not reported.66.globl test_dead67.section .test_dead,"ax",@progbits68test_dead:69 jmp test_dead70 71# RUN: ld.lld a.o a.so --gc-sections --why-live=test_dead | count 072 73## Undefined symbols are considered live, since they are not in dead sections.74 75# RUN: ld.lld a.o a.so --gc-sections --why-live=test_undef -u test_undef | FileCheck %s --check-prefix=UNDEFINED76 77# UNDEFINED: live symbol: <internal>:(test_undef) (no section)78# UNDEFINED-EMPTY:79 80## Defined symbols without input section parents are live.81.globl test_absolute82test_absolute = 123483 84# RUN: ld.lld a.o a.so --gc-sections --why-live=test_absolute | FileCheck %s --check-prefix=ABSOLUTE85 86# ABSOLUTE: live symbol: a.o:(test_absolute) (no section)87# ABSOLUTE-EMPTY:88 89## Retained sections are intrinsically live, and they make contained symbols live.90.globl test_retained91.section .test_retained,"axR",@progbits92test_retained:93 jmp test_retained94 95# RUN: ld.lld a.o a.so --gc-sections --why-live=test_retained | FileCheck %s --check-prefix=RETAINED96 97# RETAINED: live symbol: a.o:(test_retained)98# RETAINED-NEXT: >>> in live section: a.o:(.test_retained) (retained)99# RETAINED-EMPTY:100 101## Relocs that reference offsets from sections (e.g., from anonymous symbols) are considered to point to the section if no enclosing symbol exists.102 103.globl test_section_offset104.section .test_section_offset,"ax",@progbits105test_section_offset:106 jmp test_section_offset107.Lanonymous:108 jmp test_section_offset109 110# RUN: ld.lld a.o a.so --gc-sections --why-live=test_section_offset | FileCheck %s --check-prefix=SECTION-OFFSET111 112# SECTION-OFFSET: live symbol: a.o:(test_section_offset)113# SECTION-OFFSET-NEXT: >>> in live section: a.o:(.test_section_offset)114# SECTION-OFFSET-NEXT: >>> referenced by: a.o:(_start) (entry point)115# SECTION-OFFSET-EMPTY:116 117## Relocs that reference offsets from sections (e.g., from anonymous symbols) are considered to point to the enclosing symbol if one exists.118 119.globl test_section_offset_within_symbol120.section .test_section_offset_within_symbol,"ax",@progbits121test_section_offset_within_symbol:122 jmp test_section_offset_within_symbol123.Lanonymous_within_symbol:124 jmp test_section_offset_within_symbol125.size test_section_offset_within_symbol, .-test_section_offset_within_symbol126 127# RUN: ld.lld a.o a.so --gc-sections --why-live=test_section_offset_within_symbol | FileCheck %s --check-prefix=SECTION-OFFSET-WITHIN-SYMBOL128 129# SECTION-OFFSET-WITHIN-SYMBOL: live symbol: a.o:(test_section_offset_within_symbol)130# SECTION-OFFSET-WITHIN-SYMBOL-NEXT: >>> referenced by: a.o:(_start) (entry point)131# SECTION-OFFSET-WITHIN-SYMBOL-EMPTY:132 133## Local symbols can be queried just like global symbols.134 135.section .test_local,"ax",@progbits136test_local:137 jmp test_local138.size test_local, .-test_local139 140# RUN: ld.lld a.o a.so --gc-sections --why-live=test_local | FileCheck %s --check-prefix=LOCAL141 142# LOCAL: live symbol: a.o:(test_local)143# LOCAL-NEXT: >>> referenced by: a.o:(_start) (entry point)144# LOCAL-EMPTY:145 146## Shared symbols147 148# RUN: ld.lld a.o a.so --gc-sections --why-live=test_shared | FileCheck %s --check-prefix=SHARED149 150# SHARED: live symbol: a.so:(test_shared)151# SHARED-NEXT: >>> referenced by: a.o:(_start) (entry point)152# SHARED-EMPTY:153 154## Globs match multiple cases. Multiple --why-live flags union.155 156# RUN: ld.lld a.o a.so --gc-sections --why-live="test_se*" --why-live="test_se*" | FileCheck %s --check-prefix=MULTIPLE157# RUN: ld.lld a.o a.so --gc-sections --why-live=test_section_offset --why-live=test_section_offset_within_symbol | FileCheck %s --check-prefix=MULTIPLE158 159# MULTIPLE-DAG: live symbol: a.o:(test_section_offset)160# MULTIPLE-DAG: live symbol: a.o:(test_section_offset_within_symbol)161# MULTIPLE-NOT: live symbol162