... using the temporary section type code 0x40000020 (`clang -c -Wa,--crel,--allow-experimental-crel`). LLVM will change the code and break compatibility (Clang and lld of different versions are not guaranteed to cooperate, unlike other features). CREL with implicit addends are not supported. --- Introduce `RelsOrRelas::crels` to iterate over SHT_CREL sections and update users to check `crels`. (The decoding performance is critical and error checking is difficult. Follow `skipLeb` and `R_*LEB128` handling, do not use `llvm::decodeULEB128`, whichs compiles to a lot of code.) A few users (e.g. .eh_frame, LLDDwarfObj, s390x) require random access. Pass `/*supportsCrel=*/false` to `relsOrRelas` to allocate a buffer and convert CREL to RELA (`relas` instead of `crels` will be used). Since allocating a buffer increases, the conversion is only performed when absolutely necessary. --- Non-alloc SHT_CREL sections may be created in -r and --emit-relocs links. SHT_CREL and SHT_RELA components need reencoding since r_offset/r_symidx/r_type/r_addend may change. (r_type may change because relocations referencing a symbol in a discarded section are converted to `R_*_NONE`). * SHT_CREL components: decode with `RelsOrRelas` and re-encode (`OutputSection::finalizeNonAllocCrel`) * SHT_RELA components: convert to CREL (`relToCrel`). An output section can only have one relocation section. * SHT_REL components: print an error for now. SHT_REL to SHT_CREL conversion for -r/--emit-relocs is complex and unsupported yet. Link: https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600 Pull Request: https://github.com/llvm/llvm-project/pull/98115
191 lines
4.0 KiB
ArmAsm
191 lines
4.0 KiB
ArmAsm
# REQUIRES: x86
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
|
|
# RUN: ld.lld %t -o %t2
|
|
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=NOGC %s
|
|
# RUN: ld.lld --gc-sections --print-gc-sections %t -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
|
|
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC1 %s
|
|
# RUN: ld.lld --export-dynamic --gc-sections %t -o %t2
|
|
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC2 %s
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 --crel %s -o %t.o
|
|
# RUN: ld.lld --gc-sections --print-gc-sections %t.o -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
|
|
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC1 %s
|
|
|
|
# NOGC: Name: .eh_frame
|
|
# NOGC: Name: .text
|
|
# NOGC: Name: .init
|
|
# NOGC: Name: .init_x
|
|
# NOGC: Name: .fini
|
|
# NOGC: Name: .tdata
|
|
# NOGC: Name: .tbss
|
|
# NOGC: Name: .ctors
|
|
# NOGC: Name: .dtors
|
|
# NOGC: Name: .fini_array
|
|
# NOGC: Name: .init_array
|
|
# NOGC: Name: .preinit_array
|
|
# NOGC: Name: .jcr
|
|
# NOGC: Name: .jcr_x
|
|
# NOGC: Name: .debug_pubtypes
|
|
# NOGC: Name: .comment
|
|
# NOGC: Name: a
|
|
# NOGC: Name: b
|
|
# NOGC: Name: c
|
|
# NOGC: Name: e
|
|
# NOGC: Name: f
|
|
# NOGC: Name: g
|
|
# NOGC: Name: h
|
|
# NOGC: Name: x
|
|
# NOGC: Name: y
|
|
# NOGC: Name: d
|
|
|
|
# GC1-DISCARD: removing unused section {{.*}}:(.text.d)
|
|
# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.text.x)
|
|
# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.text.y)
|
|
# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.tbss.f)
|
|
# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.tdata.h)
|
|
# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.init_x)
|
|
# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.jcr_x)
|
|
# GC1-DISCARD-EMPTY:
|
|
|
|
# GC1: Name: .eh_frame
|
|
# GC1: Name: .text
|
|
# GC1: Name: .init
|
|
# GC1: Name: .fini
|
|
# GC1: Name: .tdata
|
|
# GC1: Name: .tbss
|
|
# GC1: Name: .ctors
|
|
# GC1: Name: .dtors
|
|
# GC1: Name: .fini_array
|
|
# GC1: Name: .init_array
|
|
# GC1: Name: .preinit_array
|
|
# GC1: Name: .jcr
|
|
# GC1: Name: .debug_pubtypes
|
|
# GC1: Name: .comment
|
|
# GC1: Name: a
|
|
# GC1: Name: b
|
|
# GC1: Name: c
|
|
# GC1: Name: e
|
|
# GC1-NOT: Name: f
|
|
# GC1: Name: g
|
|
# GC1-NOT: Name: h
|
|
# GC1-NOT: Name: x
|
|
# GC1-NOT: Name: y
|
|
# GC1-NOT: Name: d
|
|
|
|
# GC2: Name: .eh_frame
|
|
# GC2: Name: .text
|
|
# GC2: Name: .init
|
|
# GC2: Name: .fini
|
|
# GC2: Name: .tdata
|
|
# GC2: Name: .tbss
|
|
# GC2: Name: .ctors
|
|
# GC2: Name: .dtors
|
|
# GC2: Name: .fini_array
|
|
# GC2: Name: .init_array
|
|
# GC2: Name: .preinit_array
|
|
# GC2: Name: .jcr
|
|
# GC2: Name: .debug_pubtypes
|
|
# GC2: Name: .comment
|
|
# GC2: Name: a
|
|
# GC2: Name: b
|
|
# GC2: Name: c
|
|
# GC2: Name: e
|
|
# GC2-NOT: Name: f
|
|
# GC2: Name: g
|
|
# GC2-NOT: Name: h
|
|
# GC2-NOT: Name: x
|
|
# GC2-NOT: Name: y
|
|
# GC2: Name: d
|
|
|
|
.globl _start, d
|
|
.protected a, b, c, e, f, g, h, x, y
|
|
_start:
|
|
call a
|
|
|
|
.section .text.a,"ax",@progbits
|
|
a:
|
|
call _start
|
|
call b
|
|
|
|
.section .text.b,"ax",@progbits
|
|
b:
|
|
leaq e@tpoff(%rax),%rdx
|
|
call c
|
|
|
|
.section .text.c,"ax",@progbits
|
|
c:
|
|
leaq g@tpoff(%rax),%rdx
|
|
|
|
.section .text.d,"ax",@progbits
|
|
d:
|
|
nop
|
|
|
|
.section .text.x,"ax",@progbits
|
|
x:
|
|
call y
|
|
|
|
.section .text.y,"ax",@progbits
|
|
y:
|
|
call x
|
|
|
|
.section .tbss.e,"awT",@nobits
|
|
e:
|
|
.quad 0
|
|
|
|
.section .tbss.f,"awT",@nobits
|
|
f:
|
|
.quad 0
|
|
|
|
.section .tdata.g,"awT",@progbits
|
|
g:
|
|
.quad 0
|
|
|
|
.section .tdata.h,"awT",@progbits
|
|
h:
|
|
.quad 0
|
|
|
|
.section .ctors,"aw",@progbits
|
|
.quad 0
|
|
|
|
.section .dtors,"aw",@progbits
|
|
.quad 0
|
|
|
|
.section .init,"ax"
|
|
.quad 0
|
|
|
|
.section .init_x,"ax"
|
|
.quad 0
|
|
|
|
.section .fini,"ax"
|
|
.quad 0
|
|
|
|
.section .fini_array,"aw",@fini_array
|
|
.quad 0
|
|
|
|
# https://golang.org/cl/373734
|
|
.section .init_array,"aw",@progbits
|
|
.quad 0
|
|
|
|
# Work around https://github.com/rust-lang/rust/issues/92181
|
|
.section .init_array.00001,"aw",@progbits
|
|
.quad 0
|
|
|
|
.section .preinit_array,"aw",@preinit_array
|
|
.quad 0
|
|
|
|
.section .jcr,"aw"
|
|
.quad 0
|
|
|
|
.section .jcr_x,"aw"
|
|
.quad 0
|
|
|
|
.section .eh_frame,"a",@unwind
|
|
.quad 0
|
|
|
|
.section .debug_pubtypes,"",@progbits
|
|
.quad 0
|
|
|
|
.section .comment,"MS",@progbits,8
|
|
.quad 0
|