File tree 3 files changed +39
-0
lines changed
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -756,6 +756,10 @@ template <class ELFT> uint64_t LinkerScript<ELFT>::getSymbolValue(StringRef S) {
756
756
return 0 ;
757
757
}
758
758
759
+ template <class ELFT > bool LinkerScript<ELFT>::isDefined(StringRef S) {
760
+ return Symtab<ELFT>::X->find (S) != nullptr ;
761
+ }
762
+
759
763
// Returns indices of ELF headers containing specific section, identified
760
764
// by Name. Each index is a zero based number of ELF header listed within
761
765
// PHDRS {} script block.
@@ -1490,6 +1494,14 @@ Expr ScriptParser::readPrimary() {
1490
1494
expect (" )" );
1491
1495
return [=](uint64_t Dot) { return getConstant (Tok); };
1492
1496
}
1497
+ if (Tok == " DEFINED" ) {
1498
+ expect (" (" );
1499
+ StringRef Tok = next ();
1500
+ expect (" )" );
1501
+ return [=](uint64_t Dot) {
1502
+ return ScriptBase->isDefined (Tok) ? 1 : 0 ;
1503
+ };
1504
+ }
1493
1505
if (Tok == " SEGMENT_START" ) {
1494
1506
expect (" (" );
1495
1507
next ();
Original file line number Diff line number Diff line change @@ -157,6 +157,7 @@ class LinkerScriptBase {
157
157
virtual uint64_t getOutputSectionAlign (StringRef Name) = 0;
158
158
virtual uint64_t getHeaderSize () = 0;
159
159
virtual uint64_t getSymbolValue (StringRef S) = 0;
160
+ virtual bool isDefined (StringRef S) = 0;
160
161
};
161
162
162
163
// ScriptConfiguration holds linker script parse results.
@@ -203,6 +204,7 @@ template <class ELFT> class LinkerScript final : public LinkerScriptBase {
203
204
uint64_t getOutputSectionAlign (StringRef Name) override ;
204
205
uint64_t getHeaderSize () override ;
205
206
uint64_t getSymbolValue (StringRef S) override ;
207
+ bool isDefined (StringRef S) override ;
206
208
207
209
std::vector<OutputSectionBase<ELFT> *> *OutputSections;
208
210
Original file line number Diff line number Diff line change
1
+ # REQUIRES: x86
2
+ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3
+
4
+ # RUN: echo "SECTIONS \
5
+ # RUN: { \
6
+ # RUN: . = DEFINED(defined) ? 0x11000 : .; \
7
+ # RUN: .foo : { *(.foo*) } \
8
+ # RUN: . = DEFINED(notdefined) ? 0x12000 : 0x13000; \
9
+ # RUN: .bar : { *(.bar*) } \
10
+ # RUN: }" > %t.script
11
+ # RUN: ld.lld -o %t1 --script %t.script %t
12
+ # RUN: llvm-objdump -section-headers %t1 | FileCheck %s
13
+
14
+ # CHECK: 1 .foo 00000008 0000000000011000 DATA
15
+ # CHECK: 2 .bar 00000008 0000000000013000 DATA
16
+ # CHECK: 3 .text 00000000 0000000000013008 TEXT DATA
17
+
18
+ .global defined
19
+ defined = 0
20
+
21
+ .section .foo,"a"
22
+ .quad 1
23
+
24
+ .section .bar,"a"
25
+ .quad 1
You can’t perform that action at this time.
0 commit comments