[lld] r284470 - [ELF] - Linkerscript: accept integer values for PHDRS types.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 03:49:50 PDT 2016


Author: grimar
Date: Tue Oct 18 05:49:50 2016
New Revision: 284470

URL: http://llvm.org/viewvc/llvm-project?rev=284470&view=rev
Log:
[ELF] - Linkerscript: accept integer values for PHDRS types.

Both gold and ld accepts integers instead of named constants
for PHDRS.
Patch adds support for that.

Differential revision: https://reviews.llvm.org/D25549

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/phdrs.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=284470&r1=284469&r2=284470&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Oct 18 05:49:50 2016
@@ -1706,8 +1706,14 @@ std::vector<StringRef> ScriptParser::rea
   return Phdrs;
 }
 
+// Read a program header type name. The next token must be a
+// name of a program header type or a constant (e.g. "0x3").
 unsigned ScriptParser::readPhdrType() {
   StringRef Tok = next();
+  uint64_t Val;
+  if (readInteger(Tok, Val))
+    return Val;
+
   unsigned Ret = StringSwitch<unsigned>(Tok)
                      .Case("PT_NULL", PT_NULL)
                      .Case("PT_LOAD", PT_LOAD)

Modified: lld/trunk/test/ELF/linkerscript/phdrs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/phdrs.s?rev=284470&r1=284469&r2=284470&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/phdrs.s (original)
+++ lld/trunk/test/ELF/linkerscript/phdrs.s Tue Oct 18 05:49:50 2016
@@ -47,6 +47,29 @@
 # AT-NEXT:        PF_X (0x1)
 # AT-NEXT:      ]
 
+## Check the numetic values for PHDRS.
+# RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; foo 0x11223344; } \
+# RUN:       SECTIONS { . = SIZEOF_HEADERS; .foo : { *(.*) } : text : foo}" > %t1.script
+# RUN: ld.lld -o %t2 --script %t1.script %t
+# RUN: llvm-readobj -program-headers %t2 | FileCheck --check-prefix=INT-PHDRS %s
+
+# INT-PHDRS:      ProgramHeaders [
+# INT-PHDRS:        ProgramHeader {
+# INT-PHDRS:           Type:  (0x11223344)
+# INT-PHDRS-NEXT:      Offset: 0xB0
+# INT-PHDRS-NEXT:      VirtualAddress: 0xB0
+# INT-PHDRS-NEXT:      PhysicalAddress: 0xB0
+# INT-PHDRS-NEXT:      FileSize: 9
+# INT-PHDRS-NEXT:      MemSize: 9
+# INT-PHDRS-NEXT:      Flags [
+# INT-PHDRS-NEXT:        PF_R
+# INT-PHDRS-NEXT:        PF_W
+# INT-PHDRS-NEXT:        PF_X
+# INT-PHDRS-NEXT:      ]
+# INT-PHDRS-NEXT:      Alignment: 4
+# INT-PHDRS-NEXT:    }
+# INT-PHDRS-NEXT:  ]
+
 .global _start
 _start:
  nop




More information about the llvm-commits mailing list