Skip to content

Commit f4e9cf1

Browse files
MaskRaysvkeerthy
authored andcommitted
[ELF] Postpone ASSERT error
assignAddresses is executed more than once. When an ASSERT expression evaluates to zero, we should only report an error for the last assignAddresses. Make a change similar to #66854 and #96361. This change might help ClangBuiltLinux/linux#2094
1 parent 8381fce commit f4e9cf1

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,9 @@ Expr ScriptParser::readAssert() {
900900
StringRef msg = readName();
901901
expect(")");
902902

903-
return [=, s = ctx.script, &ctx = ctx]() -> ExprValue {
903+
return [=, s = ctx.script]() -> ExprValue {
904904
if (!e().getValue())
905-
Err(ctx) << msg;
905+
s->recordError(msg);
906906
return s->getDot();
907907
};
908908
}

lld/test/ELF/linkerscript/locationcountererr-arm-exidx.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# RUN: rm -rf %t && split-file %s %t && cd %t
33
# RUN: llvm-mc -filetype=obj -triple=armv7-linux-gnueabi a.s -o a.o
44

5-
## If we don't merge adjacent duplicate entries, __code_size will be negative and
6-
## . += __code_size will trigger a "move location counter backward" error.
5+
## If we don't merge adjacent duplicate entries, code_size will be negative (huge uint64_t value).
6+
## The ASSERT will fail and . += code_size will trigger a "move location counter backward" error.
77
## LLD may report more errors further down, but there is only one "move location counter backward" error.
88
# RUN: not ld.lld -z norelro -z max-page-size=4096 -T a.t a.o --no-merge-exidx-entries 2>&1 | \
99
# RUN: FileCheck %s --check-prefix=ERR --implicit-check-not=error:
1010

1111
# ERR: error: a.t:9: unable to move location counter (0x1000) backward to 0xf6c for section 'dummy1'
1212
# ERR-NEXT: error: a.t:10: unable to move location counter (0x2000) backward to 0x1f6c for section 'dummy2'
13+
# ERR-NEXT: error: assert failed
1314
# ERR-NEXT: error: a.t:14: unable to move location counter (0x4104) backward to 0x4070 for section 'code.unused_space'
1415
# ERR-NEXT: error: section '.ARM.exidx' will not fit in region 'CODE': overflowed by 148 bytes
1516
# ERR-NEXT: error: section dummy1 at 0x1000 of size 0xffffffffffffff6c exceeds available address space
@@ -62,5 +63,5 @@ SECTIONS {
6263
.text : { *(.text .text.*) } > CODE
6364
.ARM.exidx : { *(.ARM.exidx .ARM.exidx.*) } > CODE
6465
code_size = code_end - .;
65-
code.unused_space (NOLOAD) : { . += code_size; } > CODE
66+
code.unused_space (NOLOAD) : { ASSERT(code_size < 16, "assert failed"); . += code_size; } > CODE
6667
}

0 commit comments

Comments
 (0)