Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -55,7 +55,9 @@ void addPredefinedSections(); bool needsGot(); + void createLoads(std::vector& Dest); std::vector createPhdrs(); + void createLinkerscriptLoads(std::vector &Dest); void assignAddresses(); void assignFileOffsets(); void setPhdrs(); @@ -919,32 +921,78 @@ return true; } +template +static PhdrEntry *addHdr(std::vector> &Dest, + unsigned Type, unsigned Flags) { + Dest.emplace_back(Type, Flags); + return &Dest.back(); +} + +template void Writer::createLoads(std::vector &Dest) { + // Add the first PT_LOAD segment for regular output sections. + uintX_t Flags = PF_R; + Phdr *Load = addHdr(Dest, PT_LOAD, Flags); + Load->add(Out::ElfHeader); + Load->add(Out::ProgramHeaders); + + for (OutputSectionBase *Sec : OutputSections) { + if (!needsPtLoad(Sec)) + continue; + + // If flags changed then we want new load segment. + uintX_t NewFlags = Sec->getPhdrFlags(); + if (Flags != NewFlags) { + Load = addHdr(Dest, PT_LOAD, NewFlags); + Flags = NewFlags; + } + + Load->add(Sec); + } +} + +template +void Writer::createLinkerscriptLoads(std::vector &Dest) { + // Create text segment. All non-writable sections will be put inside. + Phdr *Load = addHdr(Dest, PT_LOAD, PF_R); + Load->add(Out::ElfHeader); + Load->add(Out::ProgramHeaders); + + for (OutputSectionBase *Sec : OutputSections) { + if (!needsPtLoad(Sec)) + continue; + + // If current load is not writable and we met section that is + // writable, create new data segment to place this and all following + // sections to. + uintX_t NewFlags = Sec->getPhdrFlags(); + if (((Load->H.p_flags & PF_W) == 0) && ((NewFlags & PF_W) != 0)) + Load = addHdr(Dest, PT_LOAD, NewFlags); + + // Merge access flags and add section to load. + Load->H.p_flags |= NewFlags; + Load->add(Sec); + } +} + // Decide which program headers to create and which sections to include in each // one. -template -std::vector> Writer::createPhdrs() { +template std::vector> Writer::createPhdrs() { std::vector Ret; - auto AddHdr = [&](unsigned Type, unsigned Flags) -> Phdr * { - Ret.emplace_back(Type, Flags); - return &Ret.back(); - }; - // The first phdr entry is PT_PHDR which describes the program header itself. - Phdr &Hdr = *AddHdr(PT_PHDR, PF_R); + Phdr &Hdr = *addHdr(Ret, PT_PHDR, PF_R); Hdr.add(Out::ProgramHeaders); // PT_INTERP must be the second entry if exists. if (Out::Interp) { - Phdr &Hdr = *AddHdr(PT_INTERP, Out::Interp->getPhdrFlags()); + Phdr &Hdr = *addHdr(Ret, PT_INTERP, Out::Interp->getPhdrFlags()); Hdr.add(Out::Interp); } - // Add the first PT_LOAD segment for regular output sections. - uintX_t Flags = PF_R; - Phdr *Load = AddHdr(PT_LOAD, Flags); - Load->add(Out::ElfHeader); - Load->add(Out::ProgramHeaders); + if (ScriptConfig->HasContents) + createLinkerscriptLoads(Ret); + else + createLoads(Ret); Phdr TlsHdr(PT_TLS, PF_R); Phdr RelRo(PT_GNU_RELRO, PF_R); @@ -962,15 +1010,6 @@ if (!needsPtLoad(Sec)) continue; - // If flags changed then we want new load segment. - uintX_t NewFlags = Sec->getPhdrFlags(); - if (Flags != NewFlags) { - Load = AddHdr(PT_LOAD, NewFlags); - Flags = NewFlags; - } - - Load->add(Sec); - if (isRelroSection(Sec)) RelRo.add(Sec); if (Sec->getType() == SHT_NOTE) @@ -983,7 +1022,7 @@ // Add an entry for .dynamic. if (Out::DynSymTab) { - Phdr &H = *AddHdr(PT_DYNAMIC, Out::Dynamic->getPhdrFlags()); + Phdr &H = *addHdr(Ret, PT_DYNAMIC, Out::Dynamic->getPhdrFlags()); H.add(Out::Dynamic); } @@ -994,14 +1033,15 @@ // PT_GNU_EH_FRAME is a special section pointing on .eh_frame_hdr. if (!Out::EhFrame->empty() && Out::EhFrameHdr) { - Phdr &Hdr = *AddHdr(PT_GNU_EH_FRAME, Out::EhFrameHdr->getPhdrFlags()); + Phdr &Hdr = + *addHdr(Ret, PT_GNU_EH_FRAME, Out::EhFrameHdr->getPhdrFlags()); Hdr.add(Out::EhFrameHdr); } // PT_GNU_STACK is a special section to tell the loader to make the // pages for the stack non-executable. if (!Config->ZExecStack) - AddHdr(PT_GNU_STACK, PF_R | PF_W); + addHdr(Ret, PT_GNU_STACK, PF_R | PF_W); if (Note.First) Ret.push_back(std::move(Note)); Index: test/ELF/arm-blx.s =================================================================== --- test/ELF/arm-blx.s +++ test/ELF/arm-blx.s @@ -74,9 +74,9 @@ // CHECK-THUMB: Disassembly of section .callee1: // CHECK-THUMB-NEXT: callee_low: -// CHECK-THUMB-NEXT: b4: 70 47 bx lr +// CHECK-THUMB-NEXT: 94: 70 47 bx lr // CHECK-THUMB: callee_low2: -// CHECK-THUMB-NEXT: b6: 70 47 bx lr +// CHECK-THUMB-NEXT: 96: 70 47 bx lr // CHECK-ARM: Disassembly of section .callee2: // CHECK-ARM-NEXT: callee_arm_low: @@ -84,10 +84,10 @@ // CHECK-ARM: Disassembly of section .caller: // CHECK-ARM-NEXT: _start: -// CHECK-ARM-NEXT: 10000: 2b c0 ff fa blx #-65364 -// CHECK-ARM-NEXT: 10004: 2a c0 ff fa blx #-65368 -// CHECK-ARM-NEXT: 10008: 29 c0 ff fb blx #-65370 -// CHECK-ARM-NEXT: 1000c: 28 c0 ff fb blx #-65374 +// CHECK-ARM-NEXT: 10000: 23 c0 ff fa blx #-65396 +// CHECK-ARM-NEXT: 10004: 22 c0 ff fa blx #-65400 +// CHECK-ARM-NEXT: 10008: 21 c0 ff fb blx #-65402 +// CHECK-ARM-NEXT: 1000c: 20 c0 ff fb blx #-65406 // CHECK-ARM-NEXT: 10010: 3a 00 00 fa blx #232 // CHECK-ARM-NEXT: 10014: 39 00 00 fa blx #228 // CHECK-ARM-NEXT: 10018: 38 00 00 fb blx #226 Index: test/ELF/arm-branch.s =================================================================== --- test/ELF/arm-branch.s +++ test/ELF/arm-branch.s @@ -5,7 +5,7 @@ // RUN: .caller : { *(.text) } \ // RUN: .callee2 : { *(.callee_high) } } " > %t.script // RUN: ld.lld --script %t.script %t %tfar -o %t2 2>&1 -// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s +// RUN: llvm-objdump -s -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s // REQUIRES: arm .syntax unified .section .callee_low, "ax",%progbits @@ -38,12 +38,12 @@ // CHECK: Disassembly of section .caller: // CHECK-NEXT: _start: -// S(callee_low) = 0xb4 P = 0x10000 A = -8 = -0xff54 = -65364 -// CHECK-NEXT: 10000: 2b c0 ff eb bl #-65364 -// S(callee_low) = 0xb4 P = 0x10004 A = -8 = -0xff58 = -65368 -// CHECK-NEXT: 10004: 2a c0 ff ea b #-65368 -// S(callee_low) = 0xb4 P = 0x10008 A = -8 = -0xff5c -65372 -// CHECK-NEXT: 10008: 29 c0 ff 0a beq #-65372 +// S(callee_low) = 0x94 P = 0x10000 A = -8 = -0xff74 = -65364 +// CHECK-NEXT: 10000: 23 c0 ff eb bl #-65396 +// S(callee_low) = 0x94 P = 0x10004 A = -8 = -0xff78 = -65400 +// CHECK-NEXT: 10004: 22 c0 ff ea b #-65400 +// S(callee_low) = 0x94 P = 0x10008 A = -8 = -0xff7c = -65404 +// CHECK-NEXT: 10008: 21 c0 ff 0a beq #-65404 // S(callee_high) = 0x10028 P = 0x1000c A = -8 = 0x14 = 20 // CHECK-NEXT: 1000c: 05 00 00 eb bl #20 // S(callee_high) = 0x10028 P = 0x10010 A = -8 = 0x10 = 16 Index: test/ELF/arm-thumb-branch.s =================================================================== --- test/ELF/arm-thumb-branch.s +++ test/ELF/arm-thumb-branch.s @@ -40,12 +40,12 @@ // CHECK: Disassembly of section .callee1: // CHECK-NEXT: callee_low: -// CHECK-NEXT: b4: 70 47 bx lr +// CHECK-NEXT: 94: 70 47 bx lr // CHECK-NEXT: Disassembly of section .caller: // CHECK-NEXT: _start: -// CHECK-NEXT: 10000: f0 f7 58 f8 bl #-65360 -// CHECK-NEXT: 10004: f0 f7 56 b8 b.w #-65364 -// CHECK-NEXT: 10008: 30 f4 54 a8 beq.w #-65368 +// CHECK-NEXT: 10000: f0 f7 48 f8 bl #-65392 +// CHECK-NEXT: 10004: f0 f7 46 b8 b.w #-65396 +// CHECK-NEXT: 10008: 30 f4 44 a8 beq.w #-65400 // CHECK-NEXT: 1000c: 00 f0 0c f8 bl #24 // CHECK-NEXT: 10010: 00 f0 0a b8 b.w #20 // CHECK-NEXT: 10014: 40 f0 08 80 bne.w #16 Index: test/ELF/linkerscript/linkerscript-common.s =================================================================== --- test/ELF/linkerscript/linkerscript-common.s +++ test/ELF/linkerscript/linkerscript-common.s @@ -15,7 +15,7 @@ # CHECK-NEXT: SHF_WRITE (0x1) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x200 -# CHECK-NEXT: Offset: 0x158 +# CHECK-NEXT: Offset: 0x120 # CHECK-NEXT: Size: 256 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 Index: test/ELF/linkerscript/linkerscript-excludefile.s =================================================================== --- test/ELF/linkerscript/linkerscript-excludefile.s +++ test/ELF/linkerscript/linkerscript-excludefile.s @@ -12,15 +12,15 @@ # CHECK: Disassembly of section .text: # CHECK: _start: -# CHECK: 120: 48 c7 c0 3c 00 00 00 movq $60, %rax -# CHECK: 127: 48 c7 c7 2a 00 00 00 movq $42, %rdi -# CHECK: 12e: 00 00 addb %al, (%rax) +# CHECK: e8: 48 c7 c0 3c 00 00 00 movq $60, %rax +# CHECK: ef: 48 c7 c7 2a 00 00 00 movq $42, %rdi +# CHECK: f6: 00 00 addb %al, (%rax) # CHECK: _potato: -# CHECK: 130: 90 nop -# CHECK: 131: 90 nop -# CHECK: 132: 00 00 addb %al, (%rax) +# CHECK: f8: 90 nop +# CHECK: f9: 90 nop +# CHECK: fa: 00 00 addb %al, (%rax) # CHECK: tomato: -# CHECK: 134: b8 01 00 00 00 movl $1, %eax +# CHECK: fc: b8 01 00 00 00 movl $1, %eax # RUN: echo "SECTIONS { .patatino : \ # RUN: { KEEP(*(EXCLUDE_FILE(*notinclude) .text)) } }" \ @@ -31,15 +31,15 @@ # EXCLUDE: Disassembly of section .patatino: # EXCLUDE: _start: -# EXCLUDE: 120: 48 c7 c0 3c 00 00 00 movq $60, %rax -# EXCLUDE: 127: 48 c7 c7 2a 00 00 00 movq $42, %rdi -# EXCLUDE: 12e: 00 00 addb %al, (%rax) +# EXCLUDE: e8: 48 c7 c0 3c 00 00 00 movq $60, %rax +# EXCLUDE: ef: 48 c7 c7 2a 00 00 00 movq $42, %rdi +# EXCLUDE: f6: 00 00 addb %al, (%rax) # EXCLUDE: _potato: -# EXCLUDE: 130: 90 nop -# EXCLUDE: 131: 90 nop +# EXCLUDE: f8: 90 nop +# EXCLUDE: f9: 90 nop # EXCLUDE: Disassembly of section .text: # EXCLUDE: tomato: -# EXCLUDE: 134: b8 01 00 00 00 movl $1, %eax +# EXCLUDE: fc: b8 01 00 00 00 movl $1, %eax .section .text .globl _start Index: test/ELF/linkerscript/linkerscript-filename-spec.s =================================================================== --- test/ELF/linkerscript/linkerscript-filename-spec.s +++ test/ELF/linkerscript/linkerscript-filename-spec.s @@ -9,7 +9,7 @@ # RUN: ld.lld -o %t1 --script %t1.script %tfirst.o %tsecond.o # RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=FIRSTSECOND %s # FIRSTSECOND: Contents of section .foo: -# FIRSTSECOND-NEXT: 0120 01000000 00000000 11000000 00000000 +# FIRSTSECOND-NEXT: 01000000 00000000 11000000 00000000 # RUN: echo "SECTIONS { .foo : { \ # RUN: KEEP(*second.o(.foo)) \ @@ -17,7 +17,7 @@ # RUN: ld.lld -o %t2 --script %t2.script %tfirst.o %tsecond.o # RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SECONDFIRST %s # SECONDFIRST: Contents of section .foo: -# SECONDFIRST-NEXT: 0120 11000000 00000000 01000000 00000000 +# SECONDFIRST-NEXT: 11000000 00000000 01000000 00000000 ## Now the same tests but without KEEP. Checking that file name inside ## KEEP is parsed fine. Index: test/ELF/linkerscript/linkerscript-merge-sections.s =================================================================== --- test/ELF/linkerscript/linkerscript-merge-sections.s +++ test/ELF/linkerscript/linkerscript-merge-sections.s @@ -5,8 +5,8 @@ # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -s %t1 | FileCheck %s # CHECK: Contents of section .foo: -# CHECK-NEXT: 0158 01000000 02000000 00000000 73686f72 ............shor -# CHECK-NEXT: 0168 7420756e 7369676e 65642069 6e7400 t unsigned int. +# CHECK-NEXT: 01000000 02000000 00000000 73686f72 ............shor +# CHECK-NEXT: 7420756e 7369676e 65642069 6e7400 t unsigned int. .global _start _start: Index: test/ELF/linkerscript/linkerscript-ptloads.s =================================================================== --- test/ELF/linkerscript/linkerscript-ptloads.s +++ test/ELF/linkerscript/linkerscript-ptloads.s @@ -0,0 +1,85 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: . = ALIGN(CONSTANT(MAXPAGESIZE)); \ +# RUN: .A : { *(.A.1) } \ +# RUN: . = ALIGN(CONSTANT(MAXPAGESIZE)); \ +# RUN: .AX : { *(.AX.1) } \ +# RUN: . = ALIGN(CONSTANT(MAXPAGESIZE)); \ +# RUN: .AW : { *(.AW.1) } \ +# RUN: . = ALIGN(CONSTANT(MAXPAGESIZE)); \ +# RUN: .A2 : { *(.A.2) } \ +# RUN: . = ALIGN(CONSTANT(MAXPAGESIZE)); \ +# RUN: .AX2 : { *(.AX.2) } \ +# RUN: . = ALIGN(CONSTANT(MAXPAGESIZE)); \ +# RUN: .AW2 : { *(.AW.2) } \ +# RUN: }" > %t.script + +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -s -program-headers %t1 | \ +# RUN: FileCheck %s --check-prefix=HEADERS +# RUN: llvm-objdump -section-headers %t1 | \ +# RUN: FileCheck %s --check-prefix=SEC +# HEADERS: ProgramHeader { +# HEADERS: Type: PT_LOAD +# HEADERS-NEXT: Offset: 0x0 +# HEADERS-NEXT: VirtualAddress: 0x0 +# HEADERS-NEXT: PhysicalAddress: 0x0 +# HEADERS-NEXT: FileSize: 8200 +# HEADERS-NEXT: MemSize: 8200 +# HEADERS-NEXT: Flags [ +# HEADERS-NEXT: PF_R +# HEADERS-NEXT: PF_X +# HEADERS-NEXT: ] +# HEADERS-NEXT: Alignment: 4096 +# HEADERS-NEXT: } +# HEADERS-NEXT: ProgramHeader { +# HEADERS-NEXT: Type: PT_LOAD +# HEADERS-NEXT: Offset: 0x3000 +# HEADERS-NEXT: VirtualAddress: 0x3000 +# HEADERS-NEXT: PhysicalAddress: 0x3000 +# HEADERS-NEXT: FileSize: 12297 +# HEADERS-NEXT: MemSize: 12297 +# HEADERS-NEXT: Flags [ +# HEADERS-NEXT: PF_R +# HEADERS-NEXT: PF_W +# HEADERS-NEXT: PF_X +# HEADERS-NEXT: ] +# HEADERS-NEXT: Alignment: 4096 +# HEADERS-NEXT: } +# SEC: Sections: +# SEC-NEXT: Idx Name Size Address Type +# SEC-NEXT: 0 00000000 0000000000000000 +# SEC-NEXT: 1 .A 00000008 0000000000001000 DATA +# SEC-NEXT: 2 .AX 00000008 0000000000002000 TEXT DATA +# SEC-NEXT: 3 .AW 00000008 0000000000003000 DATA +# SEC-NEXT: 4 .A2 00000008 0000000000004000 DATA +# SEC-NEXT: 5 .AX2 00000008 0000000000005000 TEXT DATA +# SEC-NEXT: 6 .AW2 00000008 0000000000006000 DATA +# SEC-NEXT: 7 .text 00000001 0000000000006008 TEXT DATA +# SEC-NEXT: 8 .symtab 00000030 0000000000000000 +# SEC-NEXT: 9 .shstrtab 0000003a 0000000000000000 +# SEC-NEXT: 10 .strtab 00000008 0000000000000000 + +.global _start +_start: + nop + +.section .AX.1,"ax" +.quad 1 + +.section .A.1,"a" +.quad 2 + +.section .AW.1,"aw" +.quad 3 + +.section .AX.2,"ax" +.quad 1 + +.section .A.2,"a" +.quad 2 + +.section .AW.2,"aw" +.quad 3 + Index: test/ELF/linkerscript/linkerscript-repsection-va.s =================================================================== --- test/ELF/linkerscript/linkerscript-repsection-va.s +++ test/ELF/linkerscript/linkerscript-repsection-va.s @@ -7,8 +7,8 @@ # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .foo 00000008 0000000000000120 DATA -# CHECK-NEXT: 2 .text 00000001 0000000000000128 TEXT DATA +# CHECK-NEXT: 1 .foo 00000008 00000000000000e8 DATA +# CHECK-NEXT: 2 .text 00000001 00000000000000f0 TEXT DATA .global _start _start: Index: test/ELF/linkerscript/linkerscript-sections-constraint.s =================================================================== --- test/ELF/linkerscript/linkerscript-sections-constraint.s +++ test/ELF/linkerscript/linkerscript-sections-constraint.s @@ -9,8 +9,8 @@ # BASE: Sections: # BASE-NEXT: Idx Name Size Address Type # BASE-NEXT: 0 00000000 0000000000000000 -# BASE-NEXT: 1 .writable 00000004 0000000000000200 DATA -# BASE-NEXT: 2 .readable 00000004 0000000000000204 DATA +# BASE-NEXT: 1 .writable 00000004 0000000000000120 DATA +# BASE-NEXT: 2 .readable 00000004 0000000000000124 DATA # RUN: echo "SECTIONS { \ # RUN: .foo : ONLY_IF_RO { *(.foo.*) } \ @@ -22,11 +22,11 @@ # NO1: Sections: # NO1-NEXT: Idx Name Size Address Type # NO1-NEXT: 0 00000000 0000000000000000 -# NO1-NEXT: 1 .writable 00000004 0000000000000200 DATA -# NO1-NEXT: 2 .readable 00000004 0000000000000204 DATA -# NO1-NEXT: 3 .text 00000001 0000000000000208 TEXT DATA -# NO1-NEXT: 4 .foo.2 00000004 0000000000000209 DATA -# NO1-NEXT: 5 .foo.1 00000004 000000000000020d TEXT DATA +# NO1-NEXT: 1 .writable 00000004 0000000000000120 DATA +# NO1-NEXT: 2 .readable 00000004 0000000000000124 DATA +# NO1-NEXT: 3 .text 00000001 0000000000000128 TEXT DATA +# NO1-NEXT: 4 .foo.2 00000004 0000000000000129 DATA +# NO1-NEXT: 5 .foo.1 00000004 000000000000012d TEXT DATA .global _start _start: Index: test/ELF/linkerscript/linkerscript-sections-keep.s =================================================================== --- test/ELF/linkerscript/linkerscript-sections-keep.s +++ test/ELF/linkerscript/linkerscript-sections-keep.s @@ -12,8 +12,8 @@ # SECGC: Sections: # SECGC-NEXT: Idx Name Size Address Type # SECGC-NEXT: 0 00000000 0000000000000000 -# SECGC-NEXT: 1 .text 00000007 0000000000000158 TEXT DATA -# SECGC-NEXT: 2 .temp 00000004 000000000000015f DATA +# SECGC-NEXT: 1 .text 00000007 00000000000000e8 TEXT DATA +# SECGC-NEXT: 2 .temp 00000004 00000000000000ef DATA ## Now apply KEEP command to preserve the section. # RUN: echo "SECTIONS { \ @@ -26,9 +26,9 @@ # SECNOGC: Sections: # SECNOGC-NEXT: Idx Name Size Address Type # SECNOGC-NEXT: 0 00000000 0000000000000000 -# SECNOGC-NEXT: 1 .text 00000007 0000000000000158 TEXT DATA -# SECNOGC-NEXT: 2 .keep 00000004 000000000000015f DATA -# SECNOGC-NEXT: 3 .temp 00000004 0000000000000163 DATA +# SECNOGC-NEXT: 1 .text 00000007 00000000000000e8 TEXT DATA +# SECNOGC-NEXT: 2 .keep 00000004 00000000000000ef DATA +# SECNOGC-NEXT: 3 .temp 00000004 00000000000000f3 DATA ## A section name matches two entries in the SECTIONS directive. The ## first one doesn't have KEEP, the second one does. If section that have @@ -41,9 +41,9 @@ # MIXED1: Sections: # MIXED1-NEXT: Idx Name Size Address Type # MIXED1-NEXT: 0 00000000 0000000000000000 -# MIXED1-NEXT: 1 .keep 00000004 0000000000000120 DATA -# MIXED1-NEXT: 2 .temp 00000004 0000000000000124 DATA -# MIXED1-NEXT: 3 .text 00000007 0000000000000128 TEXT DATA +# MIXED1-NEXT: 1 .keep 00000004 00000000000000e8 DATA +# MIXED1-NEXT: 2 .temp 00000004 00000000000000ec DATA +# MIXED1-NEXT: 3 .text 00000007 00000000000000f0 TEXT DATA # MIXED1-NEXT: 4 .symtab 00000060 0000000000000000 # MIXED1-NEXT: 5 .shstrtab 0000002d 0000000000000000 # MIXED1-NEXT: 6 .strtab 00000012 0000000000000000 @@ -60,9 +60,9 @@ # MIXED2: Sections: # MIXED2-NEXT: Idx Name Size Address Type # MIXED2-NEXT: 0 00000000 0000000000000000 -# MIXED2-NEXT: 1 .nokeep 00000004 0000000000000120 DATA -# MIXED2-NEXT: 2 .temp 00000004 0000000000000124 DATA -# MIXED2-NEXT: 3 .text 00000007 0000000000000128 TEXT DATA +# MIXED2-NEXT: 1 .nokeep 00000004 00000000000000e8 DATA +# MIXED2-NEXT: 2 .temp 00000004 00000000000000ec DATA +# MIXED2-NEXT: 3 .text 00000007 00000000000000f0 TEXT DATA # MIXED2-NEXT: 4 .symtab 00000060 0000000000000000 # MIXED2-NEXT: 5 .shstrtab 0000002f 0000000000000000 # MIXED2-NEXT: 6 .strtab 00000012 0000000000000000 Index: test/ELF/linkerscript/linkerscript-sections-padding.s =================================================================== --- test/ELF/linkerscript/linkerscript-sections-padding.s +++ test/ELF/linkerscript/linkerscript-sections-padding.s @@ -5,25 +5,25 @@ # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x112233445566778899 }" > %t.script # RUN: ld.lld -o %t.out --script %t.script %t # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES %s -# YES: 0120 66223344 55667788 99112233 44556677 +# YES: 00f0 66223344 55667788 99112233 44556677 ## Confirming that address was correct: # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x998877665544332211 }" > %t.script # RUN: ld.lld -o %t.out --script %t.script %t # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES2 %s -# YES2: 0120 66887766 55443322 11998877 66554433 +# YES2: 00f0 66887766 55443322 11998877 66554433 ## Default padding value is 0x00: # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } }" > %t.script # RUN: ld.lld -o %t.out --script %t.script %t # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=NO %s -# NO: 0120 66000000 00000000 00000000 00000000 +# NO: 00f0 66000000 00000000 00000000 00000000 ## Decimal value. # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =777 }" > %t.script # RUN: ld.lld -o %t.out --script %t.script %t # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=DEC %s -# DEC: 0120 66000309 00000309 00000309 00000309 +# DEC: 00f0 66000309 00000309 00000309 00000309 ## Invalid hex value: # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99XX }" > %t.script Index: test/ELF/linkerscript/linkerscript-sizeof.s =================================================================== --- test/ELF/linkerscript/linkerscript-sizeof.s +++ test/ELF/linkerscript/linkerscript-sizeof.s @@ -14,12 +14,12 @@ # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .aaa 00000008 0000000000000120 DATA -# CHECK-NEXT: 2 .bbb 00000010 0000000000000128 DATA -# CHECK-NEXT: 3 .ccc 00000018 0000000000000138 DATA +# CHECK-NEXT: 1 .aaa 00000008 00000000000000e8 DATA +# CHECK-NEXT: 2 .bbb 00000010 00000000000000f0 DATA +# CHECK-NEXT: 3 .ccc 00000018 0000000000000100 DATA # CHECK: SYMBOL TABLE: # CHECK-NEXT: 0000000000000000 *UND* 00000000 -# CHECK-NEXT: 0000000000000150 .text 00000000 _start +# CHECK-NEXT: 0000000000000118 .text 00000000 _start # CHECK-NEXT: 0000000000000008 *ABS* 00000000 _aaa # CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb # CHECK-NEXT: 0000000000000018 *ABS* 00000000 _ccc Index: test/ELF/linkerscript/linkerscript-sizeofheaders.s =================================================================== --- test/ELF/linkerscript/linkerscript-sizeofheaders.s +++ test/ELF/linkerscript/linkerscript-sizeofheaders.s @@ -10,8 +10,8 @@ #CHECK: SYMBOL TABLE: #CHECK-NEXT: 0000000000000000 *UND* 00000000 -#CHECK-NEXT: 0000000000000120 .text 00000000 _start -#CHECK-NEXT: 0000000000000120 *ABS* 00000000 _size +#CHECK-NEXT: 00000000000000e8 .text 00000000 _start +#CHECK-NEXT: 00000000000000e8 *ABS* 00000000 _size .global _start _start: Index: test/ELF/linkerscript/linkerscript-sort-nested.s =================================================================== --- test/ELF/linkerscript/linkerscript-sort-nested.s +++ test/ELF/linkerscript/linkerscript-sort-nested.s @@ -8,10 +8,10 @@ # RUN: ld.lld -o %t1 --script %t1.script %t1.o %t2.o # RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=SORTED_AN %s # SORTED_AN: Contents of section .aaa: -# SORTED_AN-NEXT: 0120 01000000 00000000 00000000 00000000 -# SORTED_AN-NEXT: 0130 11000000 00000000 00000000 00000000 -# SORTED_AN-NEXT: 0140 55000000 00000000 22000000 00000000 -# SORTED_AN-NEXT: 0150 02000000 00000000 +# SORTED_AN-NEXT: 01000000 00000000 00000000 00000000 +# SORTED_AN-NEXT: 11000000 00000000 00000000 00000000 +# SORTED_AN-NEXT: 55000000 00000000 22000000 00000000 +# SORTED_AN-NEXT: 02000000 00000000 ## Check sorting first by name and then by alignment. # RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(SORT_BY_ALIGNMENT(.aaa.*))) } }" > %t2.script Index: test/ELF/linkerscript/linkerscript-sort.s =================================================================== --- test/ELF/linkerscript/linkerscript-sort.s +++ test/ELF/linkerscript/linkerscript-sort.s @@ -7,26 +7,26 @@ # RUN: ld.lld -o %t1 --script %t1.script %t2.o %t1.o # RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=UNSORTED %s # UNSORTED: Contents of section .aaa: -# UNSORTED-NEXT: 0120 55000000 00000000 00000000 00000000 -# UNSORTED-NEXT: 0130 00000000 00000000 00000000 00000000 -# UNSORTED-NEXT: 0140 11000000 00000000 33000000 00000000 -# UNSORTED-NEXT: 0150 22000000 00000000 44000000 00000000 -# UNSORTED-NEXT: 0160 05000000 00000000 01000000 00000000 -# UNSORTED-NEXT: 0170 03000000 00000000 02000000 00000000 -# UNSORTED-NEXT: 0180 04000000 00000000 +# UNSORTED-NEXT: 55000000 00000000 00000000 00000000 +# UNSORTED-NEXT: 00000000 00000000 00000000 00000000 +# UNSORTED-NEXT: 11000000 00000000 33000000 00000000 +# UNSORTED-NEXT: 22000000 00000000 44000000 00000000 +# UNSORTED-NEXT: 05000000 00000000 01000000 00000000 +# UNSORTED-NEXT: 03000000 00000000 02000000 00000000 +# UNSORTED-NEXT: 04000000 00000000 ## Check that SORT works (sorted by name of section). # RUN: echo "SECTIONS { .aaa : { *(SORT(.aaa.*)) } }" > %t2.script # RUN: ld.lld -o %t2 --script %t2.script %t2.o %t1.o # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SORTED_A %s # SORTED_A: Contents of section .aaa: -# SORTED_A-NEXT: 0120 11000000 00000000 01000000 00000000 -# SORTED_A-NEXT: 0130 22000000 00000000 02000000 00000000 -# SORTED_A-NEXT: 0140 33000000 00000000 03000000 00000000 -# SORTED_A-NEXT: 0150 44000000 00000000 00000000 00000000 -# SORTED_A-NEXT: 0160 04000000 00000000 55000000 00000000 -# SORTED_A-NEXT: 0170 00000000 00000000 00000000 00000000 -# SORTED_A-NEXT: 0180 05000000 00000000 +# SORTED_A-NEXT: 11000000 00000000 01000000 00000000 +# SORTED_A-NEXT: 22000000 00000000 02000000 00000000 +# SORTED_A-NEXT: 33000000 00000000 03000000 00000000 +# SORTED_A-NEXT: 44000000 00000000 00000000 00000000 +# SORTED_A-NEXT: 04000000 00000000 55000000 00000000 +# SORTED_A-NEXT: 00000000 00000000 00000000 00000000 +# SORTED_A-NEXT: 05000000 00000000 ## When we switch the order of files, check that sorting by ## section names is stable. @@ -34,13 +34,13 @@ # RUN: ld.lld -o %t3 --script %t3.script %t1.o %t2.o # RUN: llvm-objdump -s %t3 | FileCheck -check-prefix=SORTED_B %s # SORTED_B: Contents of section .aaa: -# SORTED_B-NEXT: 0120 01000000 00000000 00000000 00000000 -# SORTED_B-NEXT: 0130 00000000 00000000 00000000 00000000 -# SORTED_B-NEXT: 0140 11000000 00000000 02000000 00000000 -# SORTED_B-NEXT: 0150 22000000 00000000 03000000 00000000 -# SORTED_B-NEXT: 0160 33000000 00000000 00000000 00000000 -# SORTED_B-NEXT: 0170 04000000 00000000 44000000 00000000 -# SORTED_B-NEXT: 0180 05000000 00000000 55000000 00000000 +# SORTED_B-NEXT: 01000000 00000000 00000000 00000000 +# SORTED_B-NEXT: 00000000 00000000 00000000 00000000 +# SORTED_B-NEXT: 11000000 00000000 02000000 00000000 +# SORTED_B-NEXT: 22000000 00000000 03000000 00000000 +# SORTED_B-NEXT: 33000000 00000000 00000000 00000000 +# SORTED_B-NEXT: 04000000 00000000 44000000 00000000 +# SORTED_B-NEXT: 05000000 00000000 55000000 00000000 ## Check that SORT surrounded with KEEP also works. # RUN: echo "SECTIONS { .aaa : { KEEP (*(SORT(.aaa.*))) } }" > %t3.script @@ -57,14 +57,14 @@ # RUN: ld.lld -o %t5 --script %t5.script %t1.o %t2.o # RUN: llvm-objdump -s %t5 | FileCheck -check-prefix=SORTED_ALIGNMENT %s # SORTED_ALIGNMENT: Contents of section .aaa: -# SORTED_ALIGNMENT-NEXT: 0120 05000000 00000000 00000000 00000000 -# SORTED_ALIGNMENT-NEXT: 0130 00000000 00000000 00000000 00000000 -# SORTED_ALIGNMENT-NEXT: 0140 11000000 00000000 00000000 00000000 -# SORTED_ALIGNMENT-NEXT: 0150 04000000 00000000 00000000 00000000 -# SORTED_ALIGNMENT-NEXT: 0160 22000000 00000000 03000000 00000000 -# SORTED_ALIGNMENT-NEXT: 0170 33000000 00000000 02000000 00000000 -# SORTED_ALIGNMENT-NEXT: 0180 44000000 00000000 01000000 00000000 -# SORTED_ALIGNMENT-NEXT: 0190 55000000 00000000 +# SORTED_ALIGNMENT-NEXT: 05000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 00000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 11000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 04000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 22000000 00000000 03000000 00000000 +# SORTED_ALIGNMENT-NEXT: 33000000 00000000 02000000 00000000 +# SORTED_ALIGNMENT-NEXT: 44000000 00000000 01000000 00000000 +# SORTED_ALIGNMENT-NEXT: 55000000 00000000 .global _start _start: Index: test/ELF/linkerscript/linkerscript-symbol-assignexpr.s =================================================================== --- test/ELF/linkerscript/linkerscript-symbol-assignexpr.s +++ test/ELF/linkerscript/linkerscript-symbol-assignexpr.s @@ -11,8 +11,8 @@ # CHECK: SYMBOL TABLE: # CHECK-NEXT: 0000000000000000 *UND* 00000000 -# CHECK-NEXT: 0000000000000120 .text 00000000 _start -# CHECK-NEXT: 0000000000000121 .text 00000000 foo +# CHECK-NEXT: 00000000000000e8 .text 00000000 _start +# CHECK-NEXT: 00000000000000e9 .text 00000000 foo # CHECK-NEXT: 0000000000001000 *ABS* 00000000 symbol # CHECK-NEXT: 0000000000002234 *ABS* 00000000 symbol2 # CHECK-NEXT: 0000000000002234 *ABS* 00000000 symbol3 Index: test/ELF/linkerscript/linkerscript-symbol-conflict.s =================================================================== --- test/ELF/linkerscript/linkerscript-symbol-conflict.s +++ test/ELF/linkerscript/linkerscript-symbol-conflict.s @@ -4,7 +4,7 @@ # RUN: echo "SECTIONS {.text : {*(.text.*)} end = .;}" > %t.script # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -t %t1 | FileCheck %s -# CHECK: 0000000000000121 *ABS* 00000000 end +# CHECK: 00000000000000e9 *ABS* 00000000 end .global _start _start: Index: test/ELF/linkerscript/linkerscript-symbols-synthetic.s =================================================================== --- test/ELF/linkerscript/linkerscript-symbols-synthetic.s +++ test/ELF/linkerscript/linkerscript-symbols-synthetic.s @@ -19,13 +19,13 @@ # RUN: size_foo_3 = SIZEOF(.foo); }" > %t.script # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=SIMPLE %s -# SIMPLE: 0000000000000120 .foo 00000000 begin_foo -# SIMPLE-NEXT: 0000000000000128 .foo 00000000 end_foo +# SIMPLE: 00000000000000e8 .foo 00000000 begin_foo +# SIMPLE-NEXT: 00000000000000f0 .foo 00000000 end_foo # SIMPLE-NEXT: 0000000000000008 .foo 00000000 size_foo_1 # SIMPLE-NEXT: 0000000000001000 .foo 00000000 begin_bar # SIMPLE-NEXT: 0000000000001004 .foo 00000000 end_bar -# SIMPLE-NEXT: 0000000000000ee4 .foo 00000000 size_foo_2 -# SIMPLE-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_3 +# SIMPLE-NEXT: 0000000000000f1c .foo 00000000 size_foo_2 +# SIMPLE-NEXT: 0000000000000f1c *ABS* 00000000 size_foo_3 .global _start _start: Index: test/ELF/linkerscript/linkerscript-symbols.s =================================================================== --- test/ELF/linkerscript/linkerscript-symbols.s +++ test/ELF/linkerscript/linkerscript-symbols.s @@ -7,7 +7,7 @@ # RUN: echo "SECTIONS {.text : {*(.text.*)} text_end = .;}" > %t.script # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=SIMPLE %s -# SIMPLE: 0000000000000121 *ABS* 00000000 text_end +# SIMPLE: 00000000000000e9 *ABS* 00000000 text_end # The symbol is not referenced. Don't provide it. # RUN: echo "SECTIONS { PROVIDE(newsym = 1);}" > %t.script Index: test/ELF/linkerscript/linkerscript-va.s =================================================================== --- test/ELF/linkerscript/linkerscript-va.s +++ test/ELF/linkerscript/linkerscript-va.s @@ -7,9 +7,9 @@ # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .foo 00000004 0000000000000120 DATA -# CHECK-NEXT: 2 .boo 00000004 0000000000000124 DATA -# CHECK-NEXT: 3 .text 00000001 0000000000000128 TEXT DATA +# CHECK-NEXT: 1 .foo 00000004 00000000000000e8 DATA +# CHECK-NEXT: 2 .boo 00000004 00000000000000ec DATA +# CHECK-NEXT: 3 .text 00000001 00000000000000f0 TEXT DATA .global _start _start: Index: test/ELF/phdr-align.s =================================================================== --- test/ELF/phdr-align.s +++ test/ELF/phdr-align.s @@ -31,8 +31,8 @@ # CHECK-NEXT: SHF_ALLOC # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x158 -# CHECK-NEXT: Offset: 0x158 +# CHECK-NEXT: Address: 0x120 +# CHECK-NEXT: Offset: 0x120 # CHECK-NEXT: Size: 6 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -47,8 +47,8 @@ # CHECK-NEXT: SHF_ALLOC # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x15E -# CHECK-NEXT: Offset: 0x15E +# CHECK-NEXT: Address: 0x126 +# CHECK-NEXT: Offset: 0x126 # CHECK-NEXT: Size: 2 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -63,8 +63,8 @@ # CHECK-NEXT: SHF_ALLOC # CHECK-NEXT: SHF_EXECINSTR # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x160 -# CHECK-NEXT: Offset: 0x160 +# CHECK-NEXT: Address: 0x128 +# CHECK-NEXT: Offset: 0x128 # CHECK-NEXT: Size: 1 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 Index: test/ELF/wildcards.s =================================================================== --- test/ELF/wildcards.s +++ test/ELF/wildcards.s @@ -10,10 +10,10 @@ # SEC-DEFAULT: Sections: # SEC-DEFAULT-NEXT: Idx Name Size Address Type # SEC-DEFAULT-NEXT: 0 00000000 0000000000000000 -# SEC-DEFAULT-NEXT: 1 .text 00000008 0000000000000120 TEXT DATA -# SEC-DEFAULT-NEXT: 2 .abcd 00000004 0000000000000128 TEXT DATA -# SEC-DEFAULT-NEXT: 3 .ad 00000004 000000000000012c TEXT DATA -# SEC-DEFAULT-NEXT: 4 .ag 00000004 0000000000000130 TEXT DATA +# SEC-DEFAULT-NEXT: 1 .text 00000008 00000000000000e8 TEXT DATA +# SEC-DEFAULT-NEXT: 2 .abcd 00000004 00000000000000f0 TEXT DATA +# SEC-DEFAULT-NEXT: 3 .ad 00000004 00000000000000f4 TEXT DATA +# SEC-DEFAULT-NEXT: 4 .ag 00000004 00000000000000f8 TEXT DATA # SEC-DEFAULT-NEXT: 5 .symtab 00000030 0000000000000000 # SEC-DEFAULT-NEXT: 6 .shstrtab 0000002f 0000000000000000 # SEC-DEFAULT-NEXT: 7 .strtab 00000008 0000000000000000 @@ -34,9 +34,9 @@ # SEC-ALL: Sections: # SEC-ALL-NEXT: Idx Name Size Address Type # SEC-ALL-NEXT: 0 00000000 0000000000000000 -# SEC-ALL-NEXT: 1 .text 0000000c 0000000000000120 TEXT DATA -# SEC-ALL-NEXT: 2 .ad 00000004 000000000000012c TEXT DATA -# SEC-ALL-NEXT: 3 .ag 00000004 0000000000000130 TEXT DATA +# SEC-ALL-NEXT: 1 .text 0000000c 00000000000000e8 TEXT DATA +# SEC-ALL-NEXT: 2 .ad 00000004 00000000000000f4 TEXT DATA +# SEC-ALL-NEXT: 3 .ag 00000004 00000000000000f8 TEXT DATA # SEC-ALL-NEXT: 4 .symtab 00000030 0000000000000000 # SEC-ALL-NEXT: 5 .shstrtab 00000029 0000000000000000 # SEC-ALL-NEXT: 6 .strtab 00000008 0000000000000000 @@ -50,7 +50,7 @@ # SEC-NO: Sections: # SEC-NO-NEXT: Idx Name Size Address Type # SEC-NO-NEXT: 0 00000000 0000000000000000 -# SEC-NO-NEXT: 1 .text 00000014 0000000000000120 TEXT DATA +# SEC-NO-NEXT: 1 .text 00000014 00000000000000e8 TEXT DATA # SEC-NO-NEXT: 2 .symtab 00000030 0000000000000000 # SEC-NO-NEXT: 3 .shstrtab 00000021 0000000000000000 # SEC-NO-NEXT: 4 .strtab 00000008 0000000000000000