... 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
102 lines
3.4 KiB
Plaintext
102 lines
3.4 KiB
Plaintext
# REQUIRES: x86
|
|
# RUN: rm -rf %t && split-file %s %t && cd %t
|
|
|
|
# RUN: llvm-mc --triple=x86_64 -filetype=obj a.s -o a.o
|
|
# RUN: llvm-mc --triple=x86_64 -filetype=obj -crel a.s -o ac.o
|
|
# RUN: llvm-mc --triple=x86_64 -filetype=obj data.s -o data.o
|
|
# RUN: ld.lld a.o data.o -T 0.t 2>&1 | FileCheck %s --check-prefix=CHECK0 --implicit-check-not=warning:
|
|
|
|
# CHECK0: warning: 0.t:3: ignored with fewer than 2 output sections
|
|
# CHECK0-NEXT: warning: 0.t:4: ignored with fewer than 2 output sections
|
|
|
|
# RUN: not ld.lld a.o data.o -T 1.t 2>&1 | FileCheck %s --check-prefix=CHECK1 --implicit-check-not=error:
|
|
# RUN: not ld.lld ac.o data.o -T 1.t 2>&1 | FileCheck %s --check-prefix=CHECK1 --implicit-check-not=error:
|
|
# CHECK1: error: a{{.?}}.o:(.text.start+0x11): prohibited cross reference from '.text' to 'data' in '.data'
|
|
|
|
## .text and .text1 are in two NOCROSSREFS commands. Violations are reported twice.
|
|
# RUN: not ld.lld --threads=1 a.o data.o -T 2.t 2>&1 | FileCheck %s --check-prefix=CHECK2 --implicit-check-not=error:
|
|
# CHECK2: error: a.o:(.text.start+0x6): prohibited cross reference from '.text' to '.text1' in '.text1'
|
|
# CHECK2-NEXT: error: a.o:(.text.start+0x6): prohibited cross reference from '.text' to '.text1' in '.text1'
|
|
# CHECK2-NEXT: error: a.o:(.text.start+0xb): prohibited cross reference from '.text' to 'foo2' in '.text2'
|
|
# CHECK2-NEXT: error: a.o:(.text.start+0x11): prohibited cross reference from '.text' to 'data' in '.data'
|
|
# CHECK2-NEXT: error: a.o:(.text.start+0x17): prohibited cross reference from '.text' to 'str1' in '.rodata'
|
|
## .data occurs twice in the command, but the violation is only reported once.
|
|
# CHECK2-NEXT: error: a.o:(.text1+0x1): prohibited cross reference from '.text1' to '_edata' in '.data'
|
|
# CHECK2-NEXT: error: a.o:(.nonalloc+0x0): prohibited cross reference from '.nonalloc' to '.text' in '.text'
|
|
# CHECK2-NEXT: error: a.o:(.nonalloc+0x10): prohibited cross reference from '.nonalloc' to 'data' in '.data'
|
|
|
|
# RUN: not ld.lld a.o data.o -T 3.t 2>&1 | FileCheck %s --check-prefix=CHECK3 --implicit-check-not=error:
|
|
# CHECK3: error: a.o:(.nonalloc+0x0): prohibited cross reference from '.nonalloc' to '.text' in '.text'
|
|
|
|
#--- 0.t
|
|
## Some cases that do not cause errors.
|
|
abs = 42;
|
|
NOCROSSREFS()
|
|
NOCROSSREFS (.text)
|
|
NOCROSSREFS( .text .text3 ); ## ; is ignored
|
|
NOCROSSREFS_TO(.text .text2 .text3 .data );
|
|
NOCROSSREFS_TO (.data .text2 .text3)
|
|
|
|
#--- 1.t
|
|
abs = 42;
|
|
NOCROSSREFS(.text ".data")
|
|
|
|
#--- 2.t
|
|
abs = 42;
|
|
NOCROSSREFS(.text ".text1" .text ".text1" )
|
|
NOCROSSREFS(.text .text1 .text2 .data .rodata .data .nonalloc)
|
|
|
|
#--- 3.t
|
|
abs = 42;
|
|
NOCROSSREFS_TO(.text .text .text1 .text2 .data .nonalloc)
|
|
|
|
#--- err1.t
|
|
NOCROSSREFS )
|
|
|
|
# RUN: not ld.lld a.o data.o -T err1.t 2>&1 | FileCheck %s --check-prefix=ERR1 --implicit-check-not=error:
|
|
# ERR1: error: err1.t:1: ( expected, but got )
|
|
|
|
#--- err2.t
|
|
NOCROSSREFS(.text
|
|
|
|
# RUN: not ld.lld a.o data.o -T err2.t 2>&1 | FileCheck %s --check-prefix=ERR2 --implicit-check-not=error:
|
|
# ERR2: error: err2.t:1: unexpected EOF
|
|
|
|
#--- a.s
|
|
.global _start, foo1, foo2, foo3
|
|
.section .text.start,"ax"
|
|
_start:
|
|
call _start
|
|
call .text1
|
|
call foo2
|
|
movl data(%rip), %eax
|
|
movl str1(%rip), %eax
|
|
|
|
.section .text1,"ax"
|
|
foo1:
|
|
call _edata
|
|
|
|
.section .text2,"ax"
|
|
foo2:
|
|
call foo3
|
|
|
|
.section .text3,"ax"
|
|
foo3:
|
|
call foo2
|
|
|
|
.section .rodata.str1.1,"aMS",@progbits,1
|
|
str1:
|
|
.asciz "abc"
|
|
|
|
.section .nonalloc,""
|
|
.quad .text
|
|
.quad .text3
|
|
.quad data
|
|
|
|
#--- data.s
|
|
.section .data,"aw"
|
|
.globl data
|
|
data:
|
|
.byte 0
|
|
.quad abs
|