Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -1708,19 +1708,24 @@ unsigned ScriptParser::readPhdrType() { StringRef Tok = next(); - unsigned Ret = StringSwitch(Tok) - .Case("PT_NULL", PT_NULL) - .Case("PT_LOAD", PT_LOAD) - .Case("PT_DYNAMIC", PT_DYNAMIC) - .Case("PT_INTERP", PT_INTERP) - .Case("PT_NOTE", PT_NOTE) - .Case("PT_SHLIB", PT_SHLIB) - .Case("PT_PHDR", PT_PHDR) - .Case("PT_TLS", PT_TLS) - .Case("PT_GNU_EH_FRAME", PT_GNU_EH_FRAME) - .Case("PT_GNU_STACK", PT_GNU_STACK) - .Case("PT_GNU_RELRO", PT_GNU_RELRO) - .Default(-1); + unsigned Ret; + uint64_t Val; + if (readInteger(Tok, Val)) + Ret = Val; + else + Ret = StringSwitch(Tok) + .Case("PT_NULL", PT_NULL) + .Case("PT_LOAD", PT_LOAD) + .Case("PT_DYNAMIC", PT_DYNAMIC) + .Case("PT_INTERP", PT_INTERP) + .Case("PT_NOTE", PT_NOTE) + .Case("PT_SHLIB", PT_SHLIB) + .Case("PT_PHDR", PT_PHDR) + .Case("PT_TLS", PT_TLS) + .Case("PT_GNU_EH_FRAME", PT_GNU_EH_FRAME) + .Case("PT_GNU_STACK", PT_GNU_STACK) + .Case("PT_GNU_RELRO", PT_GNU_RELRO) + .Default(-1); if (Ret == (unsigned)-1) { setError("invalid program header type: " + Tok); Index: test/ELF/linkerscript/phdrs.s =================================================================== --- test/ELF/linkerscript/phdrs.s +++ test/ELF/linkerscript/phdrs.s @@ -47,6 +47,68 @@ # AT-NEXT: PF_X (0x1) # AT-NEXT: ] +## Check the numetic values for PHDRS. +# RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; \ +# RUN: foo1 11223344; foo2 0x11223344; foo3 0x112233440000; } \ +# RUN: SECTIONS { . = SIZEOF_HEADERS; .foo : { *(.*) } : text : foo1}" > %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-NEXT: ProgramHeader { +# INT-PHDRS-NEXT: Type: PT_LOAD +# INT-PHDRS-NEXT: Offset: 0x0 +# INT-PHDRS-NEXT: VirtualAddress: 0x0 +# INT-PHDRS-NEXT: PhysicalAddress: 0x0 +# INT-PHDRS-NEXT: FileSize: 297 +# INT-PHDRS-NEXT: MemSize: 297 +# 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: 4096 +# INT-PHDRS-NEXT: } +# INT-PHDRS-NEXT: ProgramHeader { +# INT-PHDRS-NEXT: Type: (0xAB4130) +# INT-PHDRS-NEXT: Offset: 0x120 +# INT-PHDRS-NEXT: VirtualAddress: 0x120 +# INT-PHDRS-NEXT: PhysicalAddress: 0x120 +# 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: ProgramHeader { +# INT-PHDRS-NEXT: Type: (0x11223344) +# INT-PHDRS-NEXT: Offset: 0x0 +# INT-PHDRS-NEXT: VirtualAddress: 0x0 +# INT-PHDRS-NEXT: PhysicalAddress: 0x0 +# INT-PHDRS-NEXT: FileSize: 0 +# INT-PHDRS-NEXT: MemSize: 0 +# INT-PHDRS-NEXT: Flags [ +# INT-PHDRS-NEXT: PF_R +# INT-PHDRS-NEXT: ] +# INT-PHDRS-NEXT: Alignment: 0 +# INT-PHDRS-NEXT: } +# INT-PHDRS-NEXT: ProgramHeader { +# INT-PHDRS-NEXT: Type: (0x33440000) +# INT-PHDRS-NEXT: Offset: 0x0 +# INT-PHDRS-NEXT: VirtualAddress: 0x0 +# INT-PHDRS-NEXT: PhysicalAddress: 0x0 +# INT-PHDRS-NEXT: FileSize: 0 +# INT-PHDRS-NEXT: MemSize: 0 +# INT-PHDRS-NEXT: Flags [ +# INT-PHDRS-NEXT: PF_R +# INT-PHDRS-NEXT: ] +# INT-PHDRS-NEXT: Alignment: 0 +# INT-PHDRS-NEXT: } +# INT-PHDRS-NEXT: ] + .global _start _start: nop