mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-21 17:16:52 +00:00
[LLD][ELF] Support OVERLAY NOCROSSREFS (#133807)
This allows NOCROSSREFS to be specified in OVERLAY linker script descriptions. This is a particularly useful part of the OVERLAY syntax, since it's very rarely possible for one overlay section to sensibly reference another. Closes #128790
This commit is contained in:
parent
6f959a46c0
commit
e84b57dfbf
lld
@ -565,6 +565,7 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
|
||||
addrExpr = readExpr();
|
||||
expect(":");
|
||||
}
|
||||
bool noCrossRefs = consume("NOCROSSREFS");
|
||||
Expr lmaExpr = consume("AT") ? readParenExpr() : Expr{};
|
||||
expect("{");
|
||||
|
||||
@ -595,6 +596,12 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
|
||||
static_cast<OutputDesc *>(od)->osec.memoryRegionName =
|
||||
std::string(regionName);
|
||||
}
|
||||
if (noCrossRefs) {
|
||||
NoCrossRefCommand cmd;
|
||||
for (SectionCommand *od : v)
|
||||
cmd.outputSections.push_back(static_cast<OutputDesc *>(od)->osec.name);
|
||||
ctx.script->noCrossRefs.push_back(std::move(cmd));
|
||||
}
|
||||
|
||||
// According to the specification, at the end of the overlay, the location
|
||||
// counter should be equal to the overlay base address plus size of the
|
||||
|
@ -39,6 +39,9 @@ ELF Improvements
|
||||
items that kept it live during garbage collection. This is inspired by the
|
||||
Mach-O LLD feature of the same name.
|
||||
|
||||
* Linker script ``OVERLAY`` descriptions now support virtual memory regions
|
||||
(e.g. ``>region``) and ``NOCROSSREFS``.
|
||||
|
||||
Breaking changes
|
||||
----------------
|
||||
|
||||
|
@ -28,6 +28,10 @@
|
||||
# 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'
|
||||
|
||||
# RUN: not ld.lld a.o data.o -T overlay.t 2>&1 | FileCheck %s --check-prefix=OVERLAY --implicit-check-not=error:
|
||||
# OVERLAY: error: a.o:(.text.start+0x11): prohibited cross reference from '.text' to 'data' in '.data'
|
||||
# OVERLAY-NEXT: error: a.o:(.text.start+0x17): prohibited cross reference from '.text' to 'str1' in '.rodata'
|
||||
|
||||
#--- 0.t
|
||||
## Some cases that do not cause errors.
|
||||
abs = 42;
|
||||
@ -50,6 +54,17 @@ NOCROSSREFS(.text .text1 .text2 .data .rodata .data .nonalloc)
|
||||
abs = 42;
|
||||
NOCROSSREFS_TO(.text .text .text1 .text2 .data .nonalloc)
|
||||
|
||||
#--- overlay.t
|
||||
abs = 42;
|
||||
_edata = 43;
|
||||
SECTIONS {
|
||||
OVERLAY : NOCROSSREFS {
|
||||
.text { *(.text*) }
|
||||
.data { *(.data*) }
|
||||
.rodata { *(.rodata*) }
|
||||
}
|
||||
}
|
||||
|
||||
#--- err1.t
|
||||
NOCROSSREFS )
|
||||
|
||||
|
@ -133,3 +133,11 @@ SECTIONS {
|
||||
# RUN: not ld.lld a.o -T unclosed.lds 2>&1 | FileCheck %s --check-prefix=UNCLOSED
|
||||
# UNCLOSED: error: unclosed.lds:2: unexpected EOF
|
||||
# UNCLOSED-NOT: {{.}}
|
||||
|
||||
#--- at-nocrossrefs-order.lds
|
||||
SECTIONS { OVERLAY 0x1000 : AT(0x1234) NOCROSSREFS {} }
|
||||
|
||||
# RUN: not ld.lld a.o -T at-nocrossrefs-order.lds 2>&1 | FileCheck %s --check-prefix=AT-NOCROSSREFS-ORDER --strict-whitespace
|
||||
# AT-NOCROSSREFS-ORDER:{{.*}}error: at-nocrossrefs-order.lds:1: { expected, but got NOCROSSREFS
|
||||
# AT-NOCROSSREFS-ORDER-NEXT:>>> SECTIONS { OVERLAY 0x1000 : AT(0x1234) NOCROSSREFS {} }
|
||||
# AT-NOCROSSREFS-ORDER-NEXT:>>> ^
|
||||
|
Loading…
x
Reference in New Issue
Block a user