[PATCH] D106987: [ELF] Align the first section of a PT_TLS even if its type is SHT_NOBITS
Jessica Clarke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 28 12:38:19 PDT 2021
jrtc27 created this revision.
jrtc27 added a reviewer: MaskRay.
Herald added subscribers: arichardson, emaste.
jrtc27 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is somewhat of a repeat of D66658 <https://reviews.llvm.org/D66658> but for sections in PT_TLS
segments. Although such sections don't need to be aligned such that
address and offset are congruent modulo the page size, they do need
to be congruent modulo the segment alignment, otherwise the
whole PT_TLS will be unaligned. We therefore use the normal calculation
to determine the section's address within the PT_LOAD rather than
bailing out early due to being SHT_NOBITS.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106987
Files:
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/tls-nobits-offset.s
lld/test/ELF/tls-nobits-offset.s
Index: lld/test/ELF/tls-nobits-offset.s
===================================================================
--- lld/test/ELF/tls-nobits-offset.s
+++ lld/test/ELF/tls-nobits-offset.s
@@ -7,13 +7,12 @@
## p_offset will be set to the sh_offset field of the section. Check we align
## sh_offset to sh_addr modulo p_align, so that p_vaddr=p_offset (mod
## p_align).
-## TODO: Currently we fail to ensure this, as shown by this test
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
-# CHECK: .tbss NOBITS 0000000000211000 000158 000001 00 WAT 0 0 4096
+# CHECK: .tbss NOBITS 0000000000211000 001000 000001 00 WAT 0 0 4096
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
-# CHECK: TLS 0x000158 0x0000000000211000 0x0000000000211000 0x000000 0x000001 R 0x1000
+# CHECK: TLS 0x001000 0x0000000000211000 0x0000000000211000 0x000000 0x000001 R 0x1000
# CHECK: 02 .tbss
Index: lld/test/ELF/linkerscript/tls-nobits-offset.s
===================================================================
--- lld/test/ELF/linkerscript/tls-nobits-offset.s
+++ lld/test/ELF/linkerscript/tls-nobits-offset.s
@@ -11,17 +11,16 @@
## p_offset will be set to the sh_offset field of the section. Check we align
## sh_offset to sh_addr modulo p_align, so that p_vaddr=p_offset (mod
## p_align).
-## TODO: Currently we fail to ensure this, as shown by this test
# CHECK: Name Type Address Off Size
# CHECK-NEXT: NULL 0000000000000000 000000 000000
# CHECK-NEXT: .text PROGBITS 0000000000000000 000190 000000
# CHECK-NEXT: .sec1 PROGBITS 0000000000000000 001000 000001
-# CHECK-NEXT: .tbss NOBITS 0000000000000400 001001 000001
+# CHECK-NEXT: .tbss NOBITS 0000000000000400 001400 000001
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
# CHECK-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000001 0x000001 R 0x1000
-# CHECK-NEXT: TLS 0x001001 0x0000000000000400 0x0000000000000400 0x000000 0x000001 R 0x400
+# CHECK-NEXT: TLS 0x001400 0x0000000000000400 0x0000000000000400 0x000000 0x000001 R 0x400
# CHECK: 00 .sec1 {{$}}
# CHECK: 01 .tbss {{$}}
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -2597,9 +2597,10 @@
return alignTo(off, os->ptLoad->p_align, os->addr);
// File offsets are not significant for .bss sections other than the first one
- // in a PT_LOAD. By convention, we keep section offsets monotonically
+ // in a PT_LOAD/PT_TLS. By convention, we keep section offsets monotonically
// increasing rather than setting to zero.
- if (os->type == SHT_NOBITS)
+ if (os->type == SHT_NOBITS &&
+ (!Out::tlsPhdr || Out::tlsPhdr->firstSec != os))
return off;
// If the section is not in a PT_LOAD, we just have to align it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106987.362497.patch
Type: text/x-patch
Size: 2949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210728/cff29f41/attachment.bin>
More information about the llvm-commits
mailing list