Skip to content

Commit e84b57d

Browse files
authored
[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
1 parent 6f959a4 commit e84b57d

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
565565
addrExpr = readExpr();
566566
expect(":");
567567
}
568+
bool noCrossRefs = consume("NOCROSSREFS");
568569
Expr lmaExpr = consume("AT") ? readParenExpr() : Expr{};
569570
expect("{");
570571

@@ -595,6 +596,12 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
595596
static_cast<OutputDesc *>(od)->osec.memoryRegionName =
596597
std::string(regionName);
597598
}
599+
if (noCrossRefs) {
600+
NoCrossRefCommand cmd;
601+
for (SectionCommand *od : v)
602+
cmd.outputSections.push_back(static_cast<OutputDesc *>(od)->osec.name);
603+
ctx.script->noCrossRefs.push_back(std::move(cmd));
604+
}
598605

599606
// According to the specification, at the end of the overlay, the location
600607
// counter should be equal to the overlay base address plus size of the

lld/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ ELF Improvements
3939
items that kept it live during garbage collection. This is inspired by the
4040
Mach-O LLD feature of the same name.
4141

42+
* Linker script ``OVERLAY`` descriptions now support virtual memory regions
43+
(e.g. ``>region``) and ``NOCROSSREFS``.
44+
4245
Breaking changes
4346
----------------
4447

lld/test/ELF/linkerscript/nocrossrefs.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
# RUN: not ld.lld a.o data.o -T 3.t 2>&1 | FileCheck %s --check-prefix=CHECK3 --implicit-check-not=error:
2929
# CHECK3: error: a.o:(.nonalloc+0x0): prohibited cross reference from '.nonalloc' to '.text' in '.text'
3030

31+
# RUN: not ld.lld a.o data.o -T overlay.t 2>&1 | FileCheck %s --check-prefix=OVERLAY --implicit-check-not=error:
32+
# OVERLAY: error: a.o:(.text.start+0x11): prohibited cross reference from '.text' to 'data' in '.data'
33+
# OVERLAY-NEXT: error: a.o:(.text.start+0x17): prohibited cross reference from '.text' to 'str1' in '.rodata'
34+
3135
#--- 0.t
3236
## Some cases that do not cause errors.
3337
abs = 42;
@@ -50,6 +54,17 @@ NOCROSSREFS(.text .text1 .text2 .data .rodata .data .nonalloc)
5054
abs = 42;
5155
NOCROSSREFS_TO(.text .text .text1 .text2 .data .nonalloc)
5256

57+
#--- overlay.t
58+
abs = 42;
59+
_edata = 43;
60+
SECTIONS {
61+
OVERLAY : NOCROSSREFS {
62+
.text { *(.text*) }
63+
.data { *(.data*) }
64+
.rodata { *(.rodata*) }
65+
}
66+
}
67+
5368
#--- err1.t
5469
NOCROSSREFS )
5570

lld/test/ELF/linkerscript/overlay.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,11 @@ SECTIONS {
133133
# RUN: not ld.lld a.o -T unclosed.lds 2>&1 | FileCheck %s --check-prefix=UNCLOSED
134134
# UNCLOSED: error: unclosed.lds:2: unexpected EOF
135135
# UNCLOSED-NOT: {{.}}
136+
137+
#--- at-nocrossrefs-order.lds
138+
SECTIONS { OVERLAY 0x1000 : AT(0x1234) NOCROSSREFS {} }
139+
140+
# RUN: not ld.lld a.o -T at-nocrossrefs-order.lds 2>&1 | FileCheck %s --check-prefix=AT-NOCROSSREFS-ORDER --strict-whitespace
141+
# AT-NOCROSSREFS-ORDER:{{.*}}error: at-nocrossrefs-order.lds:1: { expected, but got NOCROSSREFS
142+
# AT-NOCROSSREFS-ORDER-NEXT:>>> SECTIONS { OVERLAY 0x1000 : AT(0x1234) NOCROSSREFS {} }
143+
# AT-NOCROSSREFS-ORDER-NEXT:>>> ^

0 commit comments

Comments
 (0)