Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/eld/Diagnostics/DiagLDScript.inc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ DIAG(fatal_modulo_by_zero, DiagnosticEngine::Fatal,
"%0: modulo by zero in expression %1")
DIAG(error_experimental_not_supported, DiagnosticEngine::Error,
"Linker has only experimental support for handling %0")
DIAG(error_negative_vma, DiagnosticEngine::Fatal,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the diagnostic severity to error here.

"VMA is negative")
DIAG(error_negative_lma, DiagnosticEngine::Fatal,
"LMA is negative")
DIAG(error_memory_region_exceeded_limit, DiagnosticEngine::Error,
"Memory region %0 exceeded limit while adding section %1")
DIAG(error_memory_region_empty, DiagnosticEngine::Error,
Expand Down
8 changes: 8 additions & 0 deletions lib/Target/CreateProgramHeaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ bool GNULDBackend::createProgramHdrs() {
// If the output section specified a VMA value.
if ((*out)->prolog().hasVMA()) {
(*out)->prolog().vma().evaluateAndRaiseError();
if ((*out)->prolog().vma().isUnaryMinus()) {
config().raise(Diag::error_negative_vma);
return true;
}
// If the output section descriptor has an alignment specified
// honor the alignment specified, the alignment would have been
// reflected in the section alignment.
Expand Down Expand Up @@ -450,6 +454,10 @@ bool GNULDBackend::createProgramHdrs() {
// Explicitly align LMA to make the code easy to read
if (useSetLMA) {
(*out)->prolog().lma().evaluateAndRaiseError();
if ((*out)->prolog().lma().isUnaryMinus()) {
config().raise(Diag::error_negative_lma);
return true;
}
pma = (*out)->prolog().lma().result();
} else if (hasVMARegion || hasLMARegion) {
ScriptMemoryRegion &R = (*out)->epilog().lmaRegion();
Expand Down
1 change: 1 addition & 0 deletions test/Common/standalone/NegativeVMA_LMA/Inputs/1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int foo() { return 1; }
3 changes: 3 additions & 0 deletions test/Common/standalone/NegativeVMA_LMA/Inputs/script.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SECTIONS {
.foo (-0x201) : AT(0x1000) { *(.text.foo) }
}
3 changes: 3 additions & 0 deletions test/Common/standalone/NegativeVMA_LMA/Inputs/script_1.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SECTIONS {
.foo (0x201) : AT(-0x1000) { *(.text.foo) }
}
11 changes: 11 additions & 0 deletions test/Common/standalone/NegativeVMA_LMA/NegativeVMA_LMA.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#--NegativeVMA_LMA.test------------------ Executable----------------#
#BEGIN_COMMENT
# Verify that the linker errors out when the VMA/LMA
# is negative.
#END_COMMENT
RUN: %clang %clangopts -c %p/Inputs/1.c -o %t1.1.o
RUN: %not %link %linkopts %t1.1.o -T %p/Inputs/script.t -o %t2_vma.out 2>&1 | %filecheck %s
RUN: %not %link %linkopts %t1.1.o -T %p/Inputs/script_1.t -o %t2_lma.out 2>&1 | %filecheck %s --check-prefix=LMA

CHECK: VMA is negative
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the VMA/LMA value in the error message as well.

LMA: LMA is negative
Loading