[llvm-branch-commits] [lld] r344926 - Merging r344368:
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 22 10:45:40 PDT 2018
Author: tstellar
Date: Mon Oct 22 10:45:40 2018
New Revision: 344926
URL: http://llvm.org/viewvc/llvm-project?rev=344926&view=rev
Log:
Merging r344368:
------------------------------------------------------------------------
r344368 | ruiu | 2018-10-12 10:07:32 -0700 (Fri, 12 Oct 2018) | 10 lines
[lld] Add more complete support for the INCLUDE command.
Patch by Ian Tessier.
This change adds INCLUDE support to the MEMORY and SECTION commands, and
to output sections, as per:
https://sourceware.org/binutils/docs/ld/File-Commands.html#File-Commands
Differential Revision: https://reviews.llvm.org/D52951
------------------------------------------------------------------------
Added:
lld/branches/release_70/test/ELF/linkerscript/memory-include.test
lld/branches/release_70/test/ELF/linkerscript/output-section-include.test
lld/branches/release_70/test/ELF/linkerscript/section-include.test
Modified:
lld/branches/release_70/ELF/ScriptParser.cpp
Modified: lld/branches/release_70/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_70/ELF/ScriptParser.cpp?rev=344926&r1=344925&r2=344926&view=diff
==============================================================================
--- lld/branches/release_70/ELF/ScriptParser.cpp (original)
+++ lld/branches/release_70/ELF/ScriptParser.cpp Mon Oct 22 10:45:40 2018
@@ -497,6 +497,9 @@ void ScriptParser::readSections() {
for (BaseCommand *Cmd : readOverlay())
V.push_back(Cmd);
continue;
+ } else if (Tok == "INCLUDE") {
+ readInclude();
+ continue;
}
if (BaseCommand *Cmd = readAssignment(Tok))
@@ -778,6 +781,8 @@ OutputSection *ScriptParser::readOutputS
Cmd->Filler = readFill();
} else if (Tok == "SORT") {
readSort();
+ } else if (Tok == "INCLUDE") {
+ readInclude();
} else if (peek() == "(") {
Cmd->SectionCommands.push_back(readInputSectionDescription(Tok));
} else {
@@ -1404,7 +1409,11 @@ uint64_t ScriptParser::readMemoryAssignm
void ScriptParser::readMemory() {
expect("{");
while (!errorCount() && !consume("}")) {
- StringRef Name = next();
+ StringRef Tok = next();
+ if (Tok == "INCLUDE") {
+ readInclude();
+ continue;
+ }
uint32_t Flags = 0;
uint32_t NegFlags = 0;
@@ -1419,10 +1428,9 @@ void ScriptParser::readMemory() {
uint64_t Length = readMemoryAssignment("LENGTH", "len", "l");
// Add the memory region to the region map.
- MemoryRegion *MR =
- make<MemoryRegion>(Name, Origin, Length, Flags, NegFlags);
- if (!Script->MemoryRegions.insert({Name, MR}).second)
- setError("region '" + Name + "' already defined");
+ MemoryRegion *MR = make<MemoryRegion>(Tok, Origin, Length, Flags, NegFlags);
+ if (!Script->MemoryRegions.insert({Tok, MR}).second)
+ setError("region '" + Tok + "' already defined");
}
}
Added: lld/branches/release_70/test/ELF/linkerscript/memory-include.test
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_70/test/ELF/linkerscript/memory-include.test?rev=344926&view=auto
==============================================================================
--- lld/branches/release_70/test/ELF/linkerscript/memory-include.test (added)
+++ lld/branches/release_70/test/ELF/linkerscript/memory-include.test Mon Oct 22 10:45:40 2018
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+# RUN: echo "RAM2 (rwx): ORIGIN = 0x3000, LENGTH = 0x100" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s
+# CHECK: .data 00000008 0000000000002000 DATA
+# CHECK: .data2 00000008 0000000000003000 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+ INCLUDE "memory-include.test.tmp.inc"
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : { *(.data*) } > RAM
+ .data2 : { QUAD(0) } > RAM2
+}
Added: lld/branches/release_70/test/ELF/linkerscript/output-section-include.test
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_70/test/ELF/linkerscript/output-section-include.test?rev=344926&view=auto
==============================================================================
--- lld/branches/release_70/test/ELF/linkerscript/output-section-include.test (added)
+++ lld/branches/release_70/test/ELF/linkerscript/output-section-include.test Mon Oct 22 10:45:40 2018
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+## Empty include file.
+# RUN: echo "" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK1
+# CHECK1: .data 00000008 0000000000002000 DATA
+
+## Non-empty include file.
+# RUN: echo "QUAD(0)" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK2
+# CHECK2: .data 00000010 0000000000002000 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : {
+ *(.data*)
+ INCLUDE "output-section-include.test.tmp.inc"
+ } > RAM
+}
Added: lld/branches/release_70/test/ELF/linkerscript/section-include.test
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_70/test/ELF/linkerscript/section-include.test?rev=344926&view=auto
==============================================================================
--- lld/branches/release_70/test/ELF/linkerscript/section-include.test (added)
+++ lld/branches/release_70/test/ELF/linkerscript/section-include.test Mon Oct 22 10:45:40 2018
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+## Empty include file.
+# RUN: echo "" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK1
+# CHECK1: .data 00000008 0000000000002000 DATA
+# CHECK1-NEXT: .data3 00000008 0000000000002008 DATA
+
+## Non-empty include file.
+# RUN: echo ".data2 : { QUAD(0) } > RAM" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK2
+# CHECK2: .data 00000008 0000000000002000 DATA
+# CHECK2-NEXT: .data2 00000008 0000000000002008 DATA
+# CHECK2-NEXT: .data3 00000008 0000000000002010 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : { *(.data*) } > RAM
+ INCLUDE "section-include.test.tmp.inc"
+ .data3 : { QUAD(0) } > RAM
+}
More information about the llvm-branch-commits
mailing list