[PATCH] D111871: [ELF] Let sections reach the end of the address space
Hristo Venev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 15 02:54:32 PDT 2021
hvenev created this revision.
hvenev added reviewers: MaskRay, psmith.
Herald added subscribers: arichardson, emaste.
hvenev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is permitted by the GNU linker.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111871
Files:
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/i386-sections-until-end-of-va.s
lld/test/ELF/linkerscript/sections-until-end-of-va.s
Index: lld/test/ELF/linkerscript/sections-until-end-of-va.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/sections-until-end-of-va.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+# RUN: echo "SECTIONS { . = 0xfffffffffffffff0;" > %t.script
+# RUN: echo " .bar : { *(.bar*) } }" >> %t.script
+# RUN: ld.lld -o /dev/null --script %t.script %t.o 2>&1
+
+## .bar section has data in [0xfffffffffffffff0, 0xfffffffffffffff0 + 0x10] ==
+## [0xfffffffffffffff0, 0]. There is no overflow.
+
+.section .bar,"ax", at progbits
+.zero 0x10
Index: lld/test/ELF/linkerscript/i386-sections-until-end-of-va.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/i386-sections-until-end-of-va.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %s -o %t.o
+
+# RUN: echo "SECTIONS { . = 0xfffffff0;" > %t.script
+# RUN: echo " .bar : { *(.bar*) } }" >> %t.script
+# RUN: ld.lld -o /dev/null --script %t.script %t.o 2>&1
+
+## .bar section has data in [0xfffffff0, 0xfffffff0 + 0x10] ==
+## [0xfffffff0, 0]. There is no overflow.
+
+.section .bar,"ax", at progbits
+.zero 0x10
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -2782,12 +2782,15 @@
// ranges and the virtual address ranges don't overlap
template <class ELFT> void Writer<ELFT>::checkSections() {
// First, check that section's VAs fit in available address space for target.
- for (OutputSection *os : outputSections)
- if ((os->addr + os->size < os->addr) ||
- (!ELFT::Is64Bits && os->addr + os->size > UINT32_MAX))
+ for (OutputSection *os : outputSections) {
+ if (os->size == 0)
+ continue;
+ uint64_t lastByte = os->addr + (os->size - 1);
+ if ((lastByte < os->addr) || (!ELFT::Is64Bits && lastByte > UINT32_MAX))
errorOrWarn("section " + os->name + " at 0x" + utohexstr(os->addr) +
" of size 0x" + utohexstr(os->size) +
" exceeds available address space");
+ }
// Check for overlapping file offsets. In this case we need to skip any
// section marked as SHT_NOBITS. These sections don't actually occupy space in
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111871.379945.patch
Type: text/x-patch
Size: 2384 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211015/83beef5f/attachment.bin>
More information about the llvm-commits
mailing list