[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
Sat Oct 16 04:25:05 PDT 2021
hvenev updated this revision to Diff 380169.
hvenev edited the summary of this revision.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111871/new/
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,13 @@
+# 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, 0x10000000000000000). The address of the last byte of
+## the section is 0xffffffffffffffff, so this is not considered 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,13 @@
+# 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, 0x100000000). The address of the last byte of the section is
+## 0xffffffff, so this is not considered overflow.
+
+.section .bar,"ax", at progbits
+.zero 0x10
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -2782,12 +2782,14 @@
// 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) {
+ // For empty sections, we want the base VA to fit.
+ uint64_t lastByte = os->addr + (os->size ? os->size - 1 : 0);
+ 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.380169.patch
Type: text/x-patch
Size: 2604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211016/fc0afd00/attachment.bin>
More information about the llvm-commits
mailing list