Skip to content

Commit b655e2c

Browse files
parth-07quic-seaswara
authored andcommitted
Add warn diagnostics for zero-sized memory regions
This commit improves linker script diagnostics by adding a warning diagnostic for zero-sized memory regions. Closes qualcomm#114 Signed-off-by: Parth Arora <[email protected]>
1 parent 84b02af commit b655e2c

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

include/eld/Diagnostics/DiagLDScript.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,5 @@ DIAG(error_non_power_of_2_value_to_align_output_section, DiagnosticEngine::Error
124124
"%0: non-power-of-2 value 0x%1 passed to ALIGN in '%2' output section description, value must "
125125
"be 0 or a power of 2")
126126
DIAG(warn_linker_script, DiagnosticEngine::Warning, "%0")
127+
DIAG(warn_memory_region_has_zero_size, DiagnosticEngine::Warning,
128+
"%0: Memory region '%1' has zero size")

lib/Object/ScriptMemoryRegion.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ void ScriptMemoryRegion::addOutputSection(const OutputSectionEntry *O) {
3636

3737
eld::Expected<void>
3838
ScriptMemoryRegion::verifyMemoryUsage(LinkerConfig &Config) {
39+
auto ExpLen = getLength();
40+
if (ExpLen && !ExpLen.value() && Config.showLinkerScriptWarnings()) {
41+
MemorySpec *Spec = MMemoryDesc->getMemorySpec();
42+
Expression *Length = Spec->getLength();
43+
Config.raise(Diag::warn_memory_region_has_zero_size)
44+
<< Length->getContext() << getName();
45+
}
3946
if (FirstOutputSectionExceededLimit)
4047
return std::make_unique<plugin::DiagnosticEntry>(plugin::DiagnosticEntry(
4148
Diag::error_memory_region_exceeded_limit,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MEMORY {
2+
A (ARX) : ORIGIN = 0x1000, LENGTH = 0x1 - 0x1
3+
B (AW) : ORIGIN = 0x2000, LENGTH = 0x1000
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#---ZeroSizedMemoryRegionWarn.test--------------------- Executable,LS------------------#
2+
#BEGIN_COMMENT
3+
# This test verifies that the linker emits a warning for zero sized memory
4+
# regions
5+
#END_COMMENT
6+
#START_TEST
7+
RUN: %touch %t1.1.o
8+
RUN: %link %linkopts -o %t1.1.out %t1.1.o -T %p/Inputs/script.t -Wlinker-script 2>&1 | %filecheck %s
9+
RUN: %link %linkopts -o %t1.1.out %t1.1.o -T %p/Inputs/script.t -Wno-linker-script 2>&1 | %filecheck %s --allow-empty --check-prefix NOWARNLS
10+
#END_TEST
11+
12+
CHECK: Warning: {{.*}}script.t: Memory region 'A' has zero size
13+
14+
NOWARNLS-NOT: has zero size

0 commit comments

Comments
 (0)