[lld] r304925 - [ELF] - Linkerscript: implement NOLOAD section type.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 7 09:31:09 PDT 2017
Author: grimar
Date: Wed Jun 7 11:31:08 2017
New Revision: 304925
URL: http://llvm.org/viewvc/llvm-project?rev=304925&view=rev
Log:
[ELF] - Linkerscript: implement NOLOAD section type.
This is PR32351
Each output section may have a type. The type is a keyword in parentheses.
(https://sourceware.org/binutils/docs/ld/Output-Section-Type.html#Output-Section-Type)
This patch support only one type, it is NOLOAD.
If output section has such type, we force it to be SHT_NOBITS.
More details are available on a review page.
Differential revision: https://reviews.llvm.org/D33647
Added:
lld/trunk/test/ELF/linkerscript/noload.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/ScriptParser.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=304925&r1=304924&r2=304925&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jun 7 11:31:08 2017
@@ -431,6 +431,8 @@ void LinkerScript::processCommands(Outpu
if (OutputSection *Sec = Cmd->Sec) {
assert(Sec->SectionIndex == INT_MAX);
Sec->SectionIndex = I;
+ if (Cmd->Noload)
+ Sec->Type = SHT_NOBITS;
SecToCommand[Sec] = Cmd;
}
}
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=304925&r1=304924&r2=304925&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Wed Jun 7 11:31:08 2017
@@ -134,6 +134,7 @@ struct OutputSectionCommand : BaseComman
ConstraintKind Constraint = ConstraintKind::NoConstraint;
std::string Location;
std::string MemoryRegionName;
+ bool Noload = false;
template <class ELFT> void finalize();
template <class ELFT> void writeTo(uint8_t *Buf);
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=304925&r1=304924&r2=304925&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Wed Jun 7 11:31:08 2017
@@ -568,10 +568,20 @@ ScriptParser::readOutputSectionDescripti
OutputSectionCommand *Cmd =
Script->createOutputSectionCommand(OutSec, getCurrentLocation());
- // Read an address expression.
- // https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
- if (peek() != ":")
- Cmd->AddrExpr = readExpr();
+ if (peek() != ":") {
+ // Read an address expression.
+ // https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
+ if (peek() != "(")
+ Cmd->AddrExpr = readExpr();
+
+ // Read a section type. Currently, only NOLOAD is supported.
+ // https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
+ if (consume("(")) {
+ expect("NOLOAD");
+ expect(")");
+ Cmd->Noload = true;
+ }
+ }
expect(":");
Added: lld/trunk/test/ELF/linkerscript/noload.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/noload.s?rev=304925&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/noload.s (added)
+++ lld/trunk/test/ELF/linkerscript/noload.s Wed Jun 7 11:31:08 2017
@@ -0,0 +1,46 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { \
+# RUN: .data_noload_a (NOLOAD) : { *(.data_noload_a) } \
+# RUN: .data_noload_b 0x10000 (NOLOAD) : { *(.data_noload_b) } };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj --symbols -sections %t
+
+# CHECK: Section {
+# CHECK-NEXT: Index: 2
+# CHECK-NEXT: Name: .data_noload_a
+# CHECK-NEXT: Type: SHT_NOBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: SHF_WRITE
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x0
+# CHECK-NEXT: Offset: 0x1000
+# CHECK-NEXT: Size: 4096
+# CHECK-NEXT: Link: 0
+# CHECK-NEXT: Info: 0
+# CHECK-NEXT: AddressAlignment: 1
+# CHECK-NEXT: EntrySize: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Index: 3
+# CHECK-NEXT: Name: .data_noload_b
+# CHECK-NEXT: Type: SHT_NOBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: SHF_WRITE
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x10000
+# CHECK-NEXT: Offset: 0x1000
+# CHECK-NEXT: Size: 4096
+# CHECK-NEXT: Link: 0
+# CHECK-NEXT: Info: 0
+# CHECK-NEXT: AddressAlignment: 1
+# CHECK-NEXT: EntrySize: 0
+# CHECK-NEXT: }
+
+.section .data_noload_a,"aw", at progbits
+.zero 4096
+
+.section .data_noload_b,"aw", at progbits
+.zero 4096
More information about the llvm-commits
mailing list