-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lld][ELF] Allow data.rel.ro.hot and .data.rel.ro.unlikely to be RELRO
#148920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
00b0ddb
9cdf86d
27778e5
eb439b1
3b23fde
0f42025
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -553,6 +553,22 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() { | |
| } | ||
| } | ||
|
|
||
| // Returns true if the section is a data section that's read only and | ||
| // relocatable. | ||
| static bool isRelRoDataSection(Ctx &ctx, StringRef SectionName) { | ||
|
||
| // If -z keep-data-section-prefix is given, '<section>.hot' and | ||
|
||
| // '<section>.unlikely' is considered a split of '<section>' based on hotness. | ||
| // They should share the same section attributes. | ||
| if (ctx.arg.zKeepDataSectionPrefix) { | ||
| if (SectionName.ends_with(".hot")) | ||
| SectionName = SectionName.drop_back(4); | ||
| else if (SectionName.ends_with(".unlikely")) | ||
| SectionName = SectionName.drop_back(9); | ||
| } | ||
|
|
||
| return SectionName == ".data.rel.ro"; | ||
| } | ||
|
|
||
| // Today's loaders have a feature to make segments read-only after | ||
| // processing dynamic relocations to enhance security. PT_GNU_RELRO | ||
| // is defined for that. | ||
|
|
@@ -629,7 +645,7 @@ static bool isRelroSection(Ctx &ctx, const OutputSection *sec) { | |
| // magic section names. | ||
| StringRef s = sec->name; | ||
|
|
||
| bool abiAgnostic = s == ".data.rel.ro" || s == ".bss.rel.ro" || | ||
| bool abiAgnostic = isRelRoDataSection(ctx, s) || s == ".bss.rel.ro" || | ||
| s == ".ctors" || s == ".dtors" || s == ".jcr" || | ||
| s == ".eh_frame" || s == ".fini_array" || | ||
| s == ".init_array" || s == ".preinit_array"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # REQUIRES: x86 | ||
|
||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o | ||
|
|
||
| # RUN: echo "SECTIONS { \ | ||
|
||
| # RUN: .data.rel.ro : { .data.rel.ro } \ | ||
| # RUN: .data.rel.ro.unlikely : { *(.data.rel.ro.unlikely) } \ | ||
| # RUN: } INSERT AFTER .text " > %t.script | ||
|
|
||
| # RUN: ld.lld -z keep-data-section-prefix --script=%t.script %t.o -o %t | ||
|
||
| # RUN: llvm-readelf -l %t | FileCheck --check-prefix=SEG %s | ||
| # RUN: llvm-readelf -S %t | FileCheck %s | ||
|
|
||
| # There are 2 RW PT_LOAD segments. p_offset p_vaddr p_paddr p_filesz of the first | ||
|
||
| # should match PT_GNU_RELRO. | ||
| # The .data.rel.ro.unlikely section is in PT_GNU_RELRO segment. | ||
|
|
||
| # Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align | ||
| # SEG: LOAD 0x0001c8 0x00000000002011c8 0x00000000002011c8 0x000001 0x000001 R E 0x1000 | ||
| # SEG-NEXT: LOAD 0x0001c9 0x00000000002021c9 0x00000000002021c9 0x001001 0x001e37 RW 0x1000 | ||
| # SEG-NEXT: LOAD 0x0011ca 0x00000000002041ca 0x00000000002041ca 0x000001 0x000002 RW 0x1000 | ||
| # SEG-NEXT: GNU_RELRO 0x0001c9 0x00000000002021c9 0x00000000002021c9 0x001001 0x001e37 R 0x1 | ||
| # SEG-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x0 | ||
|
|
||
| # SEG: .text | ||
| # SEG-NEXT: .data.rel.ro .data.rel.ro.unlikely .relro_padding | ||
| # SEG-NEXT: .data .bss | ||
|
|
||
| # [Nr] Name Type Address Off Size | ||
| # CHECK: .data.rel.ro PROGBITS 00000000002021c9 0001c9 000001 | ||
| # CHECK-NEXT: .data.rel.ro.unlikely PROGBITS 00000000002021ca 0001ca 001000 | ||
| # CHECK-NEXT: .relro_padding NOBITS 00000000002031ca 0011ca 000e36 | ||
| # CHECK-NEXT: .data PROGBITS 00000000002041ca 0011ca 000001 | ||
| # CHECK-NEXT: .bss NOBITS 00000000002041cb 0011cb 000001 | ||
|
|
||
| .globl _start | ||
| _start: | ||
| ret | ||
|
|
||
|
|
||
| .section .data.rel.ro, "aw" | ||
| .space 1 | ||
|
|
||
|
||
| .section .data.rel.ro.unlikely, "aw" | ||
| .space 4096 | ||
|
|
||
| .section .data, "aw" | ||
| .space 1 | ||
|
|
||
| .section .bss, "aw" | ||
| .space 1 | ||
Uh oh!
There was an error while loading. Please reload this page.