Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -631,10 +631,11 @@ // * It is easy to check if a give branch was taken. // * It is easy two see how similar two ranks are (see getRankProximity). enum RankFlags { - RF_NOT_ADDR_SET = 1 << 15, - RF_NOT_INTERP = 1 << 14, - RF_NOT_ALLOC = 1 << 13, - RF_WRITE = 1 << 12, + RF_NOT_ADDR_SET = 1 << 16, + RF_NOT_INTERP = 1 << 15, + RF_NOT_ALLOC = 1 << 14, + RF_WRITE = 1 << 13, + RF_EXEC_WRITE = 1 << 12, RF_EXEC = 1 << 11, RF_NON_TLS_BSS = 1 << 10, RF_NON_TLS_BSS_RO = 1 << 9, @@ -669,19 +670,29 @@ if (!(Sec->Flags & SHF_ALLOC)) return Rank | RF_NOT_ALLOC; - // We want the read only sections first so that they go in the PT_LOAD - // covering the program headers at the start of the file. - if (Sec->Flags & SHF_WRITE) - Rank |= RF_WRITE; + // Sort sections based on their access permission in the following + // order: R, RX, RWX, RW. This order is based on the following + // considerations: + // * Read-only sections come first such that they go in the + // PT_LOAD covering the program headers at the start of the file. + // * Read-only, executable sections come next, unless the + // -no-rosegment option is used. + // * Writable, executable sections follow such that .plt on + // architectures where it needs to be writable will be placed + // between .text and .data. + // * Writable sections come last, such that .bss lands at the very + // end of the last PT_LOAD. + bool IsExec = Sec->Flags & SHF_EXECINSTR; + bool IsWrite = Sec->Flags & SHF_WRITE; - if (Sec->Flags & SHF_EXECINSTR) { - // For a corresponding reason, put non exec sections first (the program - // header PT_LOAD is not executable). - // We only do that if we are not using linker scripts, since with linker - // scripts ro and rx sections are in the same PT_LOAD, so their relative - // order is not important. The same applies for -no-rosegment. - if ((Rank & RF_WRITE) || !Config->SingleRoRx) + if (IsExec) { + if (IsWrite) + Rank |= RF_EXEC_WRITE; + else if (!Config->SingleRoRx) Rank |= RF_EXEC; + } else { + if (IsWrite) + Rank |= RF_WRITE; } // If we got here we know that both A and B are in the same PT_LOAD. Index: lld/test/ELF/amdgpu-globals.s =================================================================== --- lld/test/ELF/amdgpu-globals.s +++ lld/test/ELF/amdgpu-globals.s @@ -41,6 +41,19 @@ .long 0 ; 0x0 # CHECK: Section { +# CHECK: Name: .hsatext +# CHECK: Type: SHT_PROGBITS +# CHECK: Flags [ (0xC00007) +# CHECK: SHF_ALLOC (0x2) +# CHECK: SHF_AMDGPU_HSA_AGENT (0x800000) +# CHECK: SHF_AMDGPU_HSA_CODE (0x400000) +# CHECK: SHF_EXECINSTR (0x4) +# CHECK: SHF_WRITE (0x1) +# CHECK: ] +# CHECK: Address: [[HSATEXT_ADDR:[0-9xa-f]+]] +# CHECK: } + +# CHECK: Section { # CHECK: Name: .hsadata_global_program # CHECK: Type: SHT_PROGBITS (0x1) # CHECK: Flags [ (0x100003) @@ -60,19 +73,6 @@ # CHECK: SHF_AMDGPU_HSA_GLOBAL (0x100000) # CHECK: SHF_WRITE (0x1) # CHECK: ] -# CHECK: } - -# CHECK: Section { -# CHECK: Name: .hsatext -# CHECK: Type: SHT_PROGBITS -# CHECK: Flags [ (0xC00007) -# CHECK: SHF_ALLOC (0x2) -# CHECK: SHF_AMDGPU_HSA_AGENT (0x800000) -# CHECK: SHF_AMDGPU_HSA_CODE (0x400000) -# CHECK: SHF_EXECINSTR (0x4) -# CHECK: SHF_WRITE (0x1) -# CHECK: ] -# CHECK: Address: [[HSATEXT_ADDR:[0-9xa-f]+]] # CHECK: } # CHECK: Symbol { Index: lld/test/ELF/gc-sections.s =================================================================== --- lld/test/ELF/gc-sections.s +++ lld/test/ELF/gc-sections.s @@ -10,10 +10,10 @@ # NOGC: Name: .eh_frame # NOGC: Name: .text -# NOGC: Name: .ctors -# NOGC: Name: .dtors # NOGC: Name: .init # NOGC: Name: .fini +# NOGC: Name: .ctors +# NOGC: Name: .dtors # NOGC: Name: .debug_pubtypes # NOGC: Name: .comment # NOGC: Name: a @@ -25,10 +25,10 @@ # GC1: Name: .eh_frame # GC1: Name: .text -# GC1: Name: .ctors -# GC1: Name: .dtors # GC1: Name: .init # GC1: Name: .fini +# GC1: Name: .ctors +# GC1: Name: .dtors # GC1: Name: .debug_pubtypes # GC1: Name: .comment # GC1: Name: a @@ -40,10 +40,10 @@ # GC2: Name: .eh_frame # GC2: Name: .text -# GC2: Name: .ctors -# GC2: Name: .dtors # GC2: Name: .init # GC2: Name: .fini +# GC2: Name: .ctors +# GC2: Name: .dtors # GC2: Name: .debug_pubtypes # GC2: Name: .comment # GC2: Name: a Index: lld/test/ELF/i386-tls-ie-shared.s =================================================================== --- lld/test/ELF/i386-tls-ie-shared.s +++ lld/test/ELF/i386-tls-ie-shared.s @@ -13,8 +13,8 @@ // GOTRELSHARED-NEXT: SHF_ALLOC // GOTRELSHARED-NEXT: SHF_WRITE // GOTRELSHARED-NEXT: ] -// GOTRELSHARED-NEXT: Address: 0x1058 -// GOTRELSHARED-NEXT: Offset: 0x1058 +// GOTRELSHARED-NEXT: Address: 0x2058 +// GOTRELSHARED-NEXT: Offset: 0x2058 // GOTRELSHARED-NEXT: Size: 16 // GOTRELSHARED-NEXT: Link: 0 // GOTRELSHARED-NEXT: Info: 0 @@ -23,44 +23,44 @@ // GOTRELSHARED-NEXT: } // GOTRELSHARED: Relocations [ // GOTRELSHARED-NEXT: Section ({{.*}}) .rel.dyn { -// GOTRELSHARED-NEXT: 0x2002 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x200A R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x2013 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x201C R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x2024 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x202D R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x2036 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x203F R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x1058 R_386_TLS_TPOFF tlslocal0 0x0 -// GOTRELSHARED-NEXT: 0x105C R_386_TLS_TPOFF tlslocal1 0x0 -// GOTRELSHARED-NEXT: 0x1060 R_386_TLS_TPOFF tlsshared0 0x0 -// GOTRELSHARED-NEXT: 0x1064 R_386_TLS_TPOFF tlsshared1 0x0 +// GOTRELSHARED-NEXT: 0x1002 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x100A R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x1013 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x101C R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x1024 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x102D R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x1036 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x103F R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x2058 R_386_TLS_TPOFF tlslocal0 0x0 +// GOTRELSHARED-NEXT: 0x205C R_386_TLS_TPOFF tlslocal1 0x0 +// GOTRELSHARED-NEXT: 0x2060 R_386_TLS_TPOFF tlsshared0 0x0 +// GOTRELSHARED-NEXT: 0x2064 R_386_TLS_TPOFF tlsshared1 0x0 // GOTRELSHARED-NEXT: } // GOTRELSHARED-NEXT: ] // GOTRELSHARED: 0x6FFFFFFA RELCOUNT 8 // DISASMSHARED: Disassembly of section test: // DISASMSHARED-NEXT: _start: -// (.got)[0] = 0x2050 = 8272 -// (.got)[1] = 0x2054 = 8276 -// (.got)[2] = 0x2058 = 8280 -// (.got)[3] = 0x205C = 8284 -// DISASMSHARED-NEXT: 2000: 8b 0d 58 10 00 00 movl 4184, %ecx -// DISASMSHARED-NEXT: 2006: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 2009: a1 58 10 00 00 movl 4184, %eax -// DISASMSHARED-NEXT: 200e: 65 8b 00 movl %gs:(%eax), %eax -// DISASMSHARED-NEXT: 2011: 03 0d 58 10 00 00 addl 4184, %ecx -// DISASMSHARED-NEXT: 2017: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 201a: 8b 0d 5c 10 00 00 movl 4188, %ecx -// DISASMSHARED-NEXT: 2020: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 2023: a1 5c 10 00 00 movl 4188, %eax -// DISASMSHARED-NEXT: 2028: 65 8b 00 movl %gs:(%eax), %eax -// DISASMSHARED-NEXT: 202b: 03 0d 5c 10 00 00 addl 4188, %ecx -// DISASMSHARED-NEXT: 2031: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 2034: 8b 0d 60 10 00 00 movl 4192, %ecx -// DISASMSHARED-NEXT: 203a: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 203d: 03 0d 64 10 00 00 addl 4196, %ecx -// DISASMSHARED-NEXT: 2043: 65 8b 01 movl %gs:(%ecx), %eax +// (.got)[0] = 0x2058 = 8280 +// (.got)[1] = 0x205C = 8284 +// (.got)[2] = 0x2060 = 8288 +// (.got)[3] = 0x2064 = 8292 +// DISASMSHARED-NEXT: 1000: 8b 0d 58 20 00 00 movl 8280, %ecx +// DISASMSHARED-NEXT: 1006: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 1009: a1 58 20 00 00 movl 8280, %eax +// DISASMSHARED-NEXT: 100e: 65 8b 00 movl %gs:(%eax), %eax +// DISASMSHARED-NEXT: 1011: 03 0d 58 20 00 00 addl 8280, %ecx +// DISASMSHARED-NEXT: 1017: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 101a: 8b 0d 5c 20 00 00 movl 8284, %ecx +// DISASMSHARED-NEXT: 1020: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 1023: a1 5c 20 00 00 movl 8284, %eax +// DISASMSHARED-NEXT: 1028: 65 8b 00 movl %gs:(%eax), %eax +// DISASMSHARED-NEXT: 102b: 03 0d 5c 20 00 00 addl 8284, %ecx +// DISASMSHARED-NEXT: 1031: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 1034: 8b 0d 60 20 00 00 movl 8288, %ecx +// DISASMSHARED-NEXT: 103a: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 103d: 03 0d 64 20 00 00 addl 8292, %ecx +// DISASMSHARED-NEXT: 1043: 65 8b 01 movl %gs:(%ecx), %eax .type tlslocal0,@object .section .tbss,"awT",@nobits Index: lld/test/ELF/linkerscript/sections-constraint.s =================================================================== --- lld/test/ELF/linkerscript/sections-constraint.s +++ lld/test/ELF/linkerscript/sections-constraint.s @@ -24,8 +24,8 @@ # NO1-NEXT: 0 00000000 # NO1: .writable 00000004 # NO1: .foo.2 00000004 -# NO1: .foo.1 00000004 # NO1: .readable 00000004 +# NO1: .foo.1 00000004 .global _start _start: Index: lld/test/ELF/relocation-size-shared.s =================================================================== --- lld/test/ELF/relocation-size-shared.s +++ lld/test/ELF/relocation-size-shared.s @@ -7,48 +7,48 @@ // RELOCSHARED: Relocations [ // RELOCSHARED-NEXT: Section ({{.*}}) .rela.dyn { -// RELOCSHARED-NEXT: 0x203018 R_X86_64_SIZE64 fooshared 0xFFFFFFFFFFFFFFFF -// RELOCSHARED-NEXT: 0x203020 R_X86_64_SIZE64 fooshared 0x0 -// RELOCSHARED-NEXT: 0x203028 R_X86_64_SIZE64 fooshared 0x1 -// RELOCSHARED-NEXT: 0x203048 R_X86_64_SIZE32 fooshared 0xFFFFFFFFFFFFFFFF -// RELOCSHARED-NEXT: 0x20304F R_X86_64_SIZE32 fooshared 0x0 -// RELOCSHARED-NEXT: 0x203056 R_X86_64_SIZE32 fooshared 0x1 +// RELOCSHARED-NEXT: 0x201018 R_X86_64_SIZE64 fooshared 0xFFFFFFFFFFFFFFFF +// RELOCSHARED-NEXT: 0x201020 R_X86_64_SIZE64 fooshared 0x0 +// RELOCSHARED-NEXT: 0x201028 R_X86_64_SIZE64 fooshared 0x1 +// RELOCSHARED-NEXT: 0x201048 R_X86_64_SIZE32 fooshared 0xFFFFFFFFFFFFFFFF +// RELOCSHARED-NEXT: 0x20104F R_X86_64_SIZE32 fooshared 0x0 +// RELOCSHARED-NEXT: 0x201056 R_X86_64_SIZE32 fooshared 0x1 // RELOCSHARED-NEXT: } // RELOCSHARED-NEXT:] // DISASM: Disassembly of section test // DISASM: _data: -// DISASM-NEXT: 203000: 19 00 -// DISASM-NEXT: 203002: 00 00 -// DISASM-NEXT: 203004: 00 00 -// DISASM-NEXT: 203006: 00 00 -// DISASM-NEXT: 203008: 1a 00 -// DISASM-NEXT: 20300a: 00 00 -// DISASM-NEXT: 20300c: 00 00 -// DISASM-NEXT: 20300e: 00 00 -// DISASM-NEXT: 203010: 1b 00 -// DISASM-NEXT: 203012: 00 00 -// DISASM-NEXT: 203014: 00 00 -// DISASM-NEXT: 203016: 00 00 -// DISASM-NEXT: 203018: 00 00 -// DISASM-NEXT: 20301a: 00 00 -// DISASM-NEXT: 20301c: 00 00 -// DISASM-NEXT: 20301e: 00 00 -// DISASM-NEXT: 203020: 00 00 -// DISASM-NEXT: 203022: 00 00 -// DISASM-NEXT: 203024: 00 00 -// DISASM-NEXT: 203026: 00 00 -// DISASM-NEXT: 203028: 00 00 -// DISASM-NEXT: 20302a: 00 00 -// DISASM-NEXT: 20302c: 00 00 -// DISASM-NEXT: 20302e: 00 00 +// DISASM-NEXT: 201000: 19 00 +// DISASM-NEXT: 201002: 00 00 +// DISASM-NEXT: 201004: 00 00 +// DISASM-NEXT: 201006: 00 00 +// DISASM-NEXT: 201008: 1a 00 +// DISASM-NEXT: 20100a: 00 00 +// DISASM-NEXT: 20100c: 00 00 +// DISASM-NEXT: 20100e: 00 00 +// DISASM-NEXT: 201010: 1b 00 +// DISASM-NEXT: 201012: 00 00 +// DISASM-NEXT: 201014: 00 00 +// DISASM-NEXT: 201016: 00 00 +// DISASM-NEXT: 201018: 00 00 +// DISASM-NEXT: 20101a: 00 00 +// DISASM-NEXT: 20101c: 00 00 +// DISASM-NEXT: 20101e: 00 00 +// DISASM-NEXT: 201020: 00 00 +// DISASM-NEXT: 201022: 00 00 +// DISASM-NEXT: 201024: 00 00 +// DISASM-NEXT: 201026: 00 00 +// DISASM-NEXT: 201028: 00 00 +// DISASM-NEXT: 20102a: 00 00 +// DISASM-NEXT: 20102c: 00 00 +// DISASM-NEXT: 20102e: 00 00 // DISASM: _start: -// DISASM-NEXT: 203030: 8b 04 25 19 00 00 00 movl 25, %eax -// DISASM-NEXT: 203037: 8b 04 25 1a 00 00 00 movl 26, %eax -// DISASM-NEXT: 20303e: 8b 04 25 1b 00 00 00 movl 27, %eax -// DISASM-NEXT: 203045: 8b 04 25 00 00 00 00 movl 0, %eax -// DISASM-NEXT: 20304c: 8b 04 25 00 00 00 00 movl 0, %eax -// DISASM-NEXT: 203053: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASM-NEXT: 201030: 8b 04 25 19 00 00 00 movl 25, %eax +// DISASM-NEXT: 201037: 8b 04 25 1a 00 00 00 movl 26, %eax +// DISASM-NEXT: 20103e: 8b 04 25 1b 00 00 00 movl 27, %eax +// DISASM-NEXT: 201045: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASM-NEXT: 20104c: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASM-NEXT: 201053: 8b 04 25 00 00 00 00 movl 0, %eax .data .global foo Index: lld/test/ELF/relocation-size.s =================================================================== --- lld/test/ELF/relocation-size.s +++ lld/test/ELF/relocation-size.s @@ -11,82 +11,82 @@ // DISASM: Disassembly of section test: // DISASM-NEXT: _data: -// DISASM-NEXT: 202000: 19 00 -// DISASM-NEXT: 202002: 00 00 -// DISASM-NEXT: 202004: 00 00 -// DISASM-NEXT: 202006: 00 00 -// DISASM-NEXT: 202008: 1a 00 -// DISASM-NEXT: 20200a: 00 00 -// DISASM-NEXT: 20200c: 00 00 -// DISASM-NEXT: 20200e: 00 00 -// DISASM-NEXT: 202010: 1b 00 -// DISASM-NEXT: 202012: 00 00 -// DISASM-NEXT: 202014: 00 00 -// DISASM-NEXT: 202016: 00 00 -// DISASM-NEXT: 202018: 19 00 -// DISASM-NEXT: 20201a: 00 00 -// DISASM-NEXT: 20201c: 00 00 -// DISASM-NEXT: 20201e: 00 00 -// DISASM-NEXT: 202020: 1a 00 -// DISASM-NEXT: 202022: 00 00 -// DISASM-NEXT: 202024: 00 00 -// DISASM-NEXT: 202026: 00 00 -// DISASM-NEXT: 202028: 1b 00 -// DISASM-NEXT: 20202a: 00 00 -// DISASM-NEXT: 20202c: 00 00 -// DISASM-NEXT: 20202e: 00 00 +// DISASM-NEXT: 201000: 19 00 +// DISASM-NEXT: 201002: 00 00 +// DISASM-NEXT: 201004: 00 00 +// DISASM-NEXT: 201006: 00 00 +// DISASM-NEXT: 201008: 1a 00 +// DISASM-NEXT: 20100a: 00 00 +// DISASM-NEXT: 20100c: 00 00 +// DISASM-NEXT: 20100e: 00 00 +// DISASM-NEXT: 201010: 1b 00 +// DISASM-NEXT: 201012: 00 00 +// DISASM-NEXT: 201014: 00 00 +// DISASM-NEXT: 201016: 00 00 +// DISASM-NEXT: 201018: 19 00 +// DISASM-NEXT: 20101a: 00 00 +// DISASM-NEXT: 20101c: 00 00 +// DISASM-NEXT: 20101e: 00 00 +// DISASM-NEXT: 201020: 1a 00 +// DISASM-NEXT: 201022: 00 00 +// DISASM-NEXT: 201024: 00 00 +// DISASM-NEXT: 201026: 00 00 +// DISASM-NEXT: 201028: 1b 00 +// DISASM-NEXT: 20102a: 00 00 +// DISASM-NEXT: 20102c: 00 00 +// DISASM-NEXT: 20102e: 00 00 // DISASM: _start: -// DISASM-NEXT: 202030: 8b 04 25 19 00 00 00 movl 25, %eax -// DISASM-NEXT: 202037: 8b 04 25 1a 00 00 00 movl 26, %eax -// DISASM-NEXT: 20203e: 8b 04 25 1b 00 00 00 movl 27, %eax -// DISASM-NEXT: 202045: 8b 04 25 19 00 00 00 movl 25, %eax -// DISASM-NEXT: 20204c: 8b 04 25 1a 00 00 00 movl 26, %eax -// DISASM-NEXT: 202053: 8b 04 25 1b 00 00 00 movl 27, %eax +// DISASM-NEXT: 201030: 8b 04 25 19 00 00 00 movl 25, %eax +// DISASM-NEXT: 201037: 8b 04 25 1a 00 00 00 movl 26, %eax +// DISASM-NEXT: 20103e: 8b 04 25 1b 00 00 00 movl 27, %eax +// DISASM-NEXT: 201045: 8b 04 25 19 00 00 00 movl 25, %eax +// DISASM-NEXT: 20104c: 8b 04 25 1a 00 00 00 movl 26, %eax +// DISASM-NEXT: 201053: 8b 04 25 1b 00 00 00 movl 27, %eax // RELOCSHARED: Relocations [ // RELOCSHARED-NEXT: Section ({{.*}}) .rela.dyn { -// RELOCSHARED-NEXT: 0x3000 R_X86_64_SIZE64 foo 0xFFFFFFFFFFFFFFFF -// RELOCSHARED-NEXT: 0x3008 R_X86_64_SIZE64 foo 0x0 -// RELOCSHARED-NEXT: 0x3010 R_X86_64_SIZE64 foo 0x1 -// RELOCSHARED-NEXT: 0x3033 R_X86_64_SIZE32 foo 0xFFFFFFFFFFFFFFFF -// RELOCSHARED-NEXT: 0x303A R_X86_64_SIZE32 foo 0x0 -// RELOCSHARED-NEXT: 0x3041 R_X86_64_SIZE32 foo 0x1 +// RELOCSHARED-NEXT: 0x1000 R_X86_64_SIZE64 foo 0xFFFFFFFFFFFFFFFF +// RELOCSHARED-NEXT: 0x1008 R_X86_64_SIZE64 foo 0x0 +// RELOCSHARED-NEXT: 0x1010 R_X86_64_SIZE64 foo 0x1 +// RELOCSHARED-NEXT: 0x1033 R_X86_64_SIZE32 foo 0xFFFFFFFFFFFFFFFF +// RELOCSHARED-NEXT: 0x103A R_X86_64_SIZE32 foo 0x0 +// RELOCSHARED-NEXT: 0x1041 R_X86_64_SIZE32 foo 0x1 // RELOCSHARED-NEXT: } // RELOCSHARED-NEXT: ] // DISASMSHARED: Disassembly of section test: // DISASMSHARED-NEXT: _data: -// DISASMSHARED-NEXT: 3000: 00 00 -// DISASMSHARED-NEXT: 3002: 00 00 -// DISASMSHARED-NEXT: 3004: 00 00 -// DISASMSHARED-NEXT: 3006: 00 00 -// DISASMSHARED-NEXT: 3008: 00 00 -// DISASMSHARED-NEXT: 300a: 00 00 -// DISASMSHARED-NEXT: 300c: 00 00 -// DISASMSHARED-NEXT: 300e: 00 00 -// DISASMSHARED-NEXT: 3010: 00 00 -// DISASMSHARED-NEXT: 3012: 00 00 -// DISASMSHARED-NEXT: 3014: 00 00 -// DISASMSHARED-NEXT: 3016: 00 00 -// DISASMSHARED-NEXT: 3018: 19 00 -// DISASMSHARED-NEXT: 301a: 00 00 -// DISASMSHARED-NEXT: 301c: 00 00 -// DISASMSHARED-NEXT: 301e: 00 00 -// DISASMSHARED-NEXT: 3020: 1a 00 -// DISASMSHARED-NEXT: 3022: 00 00 -// DISASMSHARED-NEXT: 3024: 00 00 -// DISASMSHARED-NEXT: 3026: 00 00 -// DISASMSHARED-NEXT: 3028: 1b 00 -// DISASMSHARED-NEXT: 302a: 00 00 -// DISASMSHARED-NEXT: 302c: 00 00 -// DISASMSHARED-NEXT: 302e: 00 00 +// DISASMSHARED-NEXT: 1000: 00 00 +// DISASMSHARED-NEXT: 1002: 00 00 +// DISASMSHARED-NEXT: 1004: 00 00 +// DISASMSHARED-NEXT: 1006: 00 00 +// DISASMSHARED-NEXT: 1008: 00 00 +// DISASMSHARED-NEXT: 100a: 00 00 +// DISASMSHARED-NEXT: 100c: 00 00 +// DISASMSHARED-NEXT: 100e: 00 00 +// DISASMSHARED-NEXT: 1010: 00 00 +// DISASMSHARED-NEXT: 1012: 00 00 +// DISASMSHARED-NEXT: 1014: 00 00 +// DISASMSHARED-NEXT: 1016: 00 00 +// DISASMSHARED-NEXT: 1018: 19 00 +// DISASMSHARED-NEXT: 101a: 00 00 +// DISASMSHARED-NEXT: 101c: 00 00 +// DISASMSHARED-NEXT: 101e: 00 00 +// DISASMSHARED-NEXT: 1020: 1a 00 +// DISASMSHARED-NEXT: 1022: 00 00 +// DISASMSHARED-NEXT: 1024: 00 00 +// DISASMSHARED-NEXT: 1026: 00 00 +// DISASMSHARED-NEXT: 1028: 1b 00 +// DISASMSHARED-NEXT: 102a: 00 00 +// DISASMSHARED-NEXT: 102c: 00 00 +// DISASMSHARED-NEXT: 102e: 00 00 // DISASMSHARED: _start: -// DISASMSHARED-NEXT: 3030: 8b 04 25 00 00 00 00 movl 0, %eax -// DISASMSHARED-NEXT: 3037: 8b 04 25 00 00 00 00 movl 0, %eax -// DISASMSHARED-NEXT: 303e: 8b 04 25 00 00 00 00 movl 0, %eax -// DISASMSHARED-NEXT: 3045: 8b 04 25 19 00 00 00 movl 25, %eax -// DISASMSHARED-NEXT: 304c: 8b 04 25 1a 00 00 00 movl 26, %eax -// DISASMSHARED-NEXT: 3053: 8b 04 25 1b 00 00 00 movl 27, %eax +// DISASMSHARED-NEXT: 1030: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASMSHARED-NEXT: 1037: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASMSHARED-NEXT: 103e: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASMSHARED-NEXT: 1045: 8b 04 25 19 00 00 00 movl 25, %eax +// DISASMSHARED-NEXT: 104c: 8b 04 25 1a 00 00 00 movl 26, %eax +// DISASMSHARED-NEXT: 1053: 8b 04 25 1b 00 00 00 movl 27, %eax .data .global foo Index: lld/test/ELF/section-layout.s =================================================================== --- lld/test/ELF/section-layout.s +++ lld/test/ELF/section-layout.s @@ -34,6 +34,11 @@ // CHECK: Name: c // CHECK: Name: d +// Sections that are both writable and executable appear before +// sections that are only writable. +// CHECK: Name: k +// CHECK: Name: l + // Writable sections appear before TLS and other relro sections. // CHECK: Name: i @@ -42,8 +47,6 @@ // CHECK: Name: g // CHECK: Name: j -// CHECK: Name: k -// CHECK: Name: l // Non allocated sections are in input order. // CHECK: Name: t Index: lld/test/ELF/tls-i686.s =================================================================== --- lld/test/ELF/tls-i686.s +++ lld/test/ELF/tls-i686.s @@ -32,38 +32,38 @@ // DIS: Disassembly of section test: // DIS-NEXT: _start: -// DIS-NEXT: 12000: ba 08 00 00 00 movl $8, %edx -// DIS-NEXT: 12005: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 1200c: 29 d0 subl %edx, %eax -// DIS-NEXT: 1200e: ba 04 00 00 00 movl $4, %edx -// DIS-NEXT: 12013: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 1201a: 29 d0 subl %edx, %eax -// DIS-NEXT: 1201c: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 12023: 8d 81 f8 ff ff ff leal -8(%ecx), %eax -// DIS-NEXT: 12029: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 12030: 8d 81 77 00 00 00 leal 119(%ecx), %eax +// DIS-NEXT: 11000: ba 08 00 00 00 movl $8, %edx +// DIS-NEXT: 11005: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DIS-NEXT: 1100c: 29 d0 subl %edx, %eax +// DIS-NEXT: 1100e: ba 04 00 00 00 movl $4, %edx +// DIS-NEXT: 11013: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DIS-NEXT: 1101a: 29 d0 subl %edx, %eax +// DIS-NEXT: 1101c: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DIS-NEXT: 11023: 8d 81 f8 ff ff ff leal -8(%ecx), %eax +// DIS-NEXT: 11029: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DIS-NEXT: 11030: 8d 81 77 00 00 00 leal 119(%ecx), %eax // RELOC: Relocations [ // RELOC-NEXT: ] // DISSHARED: Disassembly of section test: // DISSHARED-NEXT: _start: -// DISSHARED-NEXT: 2000: ba 00 00 00 00 movl $0, %edx -// DISSHARED-NEXT: 2005: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 200c: 29 d0 subl %edx, %eax -// DISSHARED-NEXT: 200e: ba 00 00 00 00 movl $0, %edx -// DISSHARED-NEXT: 2013: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 201a: 29 d0 subl %edx, %eax -// DISSHARED-NEXT: 201c: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 2023: 8d 81 00 00 00 00 leal (%ecx), %eax -// DISSHARED-NEXT: 2029: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 2030: 8d 81 7b 00 00 00 leal 123(%ecx), %eax +// DISSHARED-NEXT: 1000: ba 00 00 00 00 movl $0, %edx +// DISSHARED-NEXT: 1005: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DISSHARED-NEXT: 100c: 29 d0 subl %edx, %eax +// DISSHARED-NEXT: 100e: ba 00 00 00 00 movl $0, %edx +// DISSHARED-NEXT: 1013: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DISSHARED-NEXT: 101a: 29 d0 subl %edx, %eax +// DISSHARED-NEXT: 101c: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DISSHARED-NEXT: 1023: 8d 81 00 00 00 00 leal (%ecx), %eax +// DISSHARED-NEXT: 1029: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx +// DISSHARED-NEXT: 1030: 8d 81 7b 00 00 00 leal 123(%ecx), %eax // RELOCSHARED: Relocations [ // RELOCSHARED-NEXT: Section (4) .rel.dyn { -// RELOCSHARED-NEXT: 0x2001 R_386_TLS_TPOFF32 var 0x0 -// RELOCSHARED-NEXT: 0x2025 R_386_TLS_TPOFF var 0x0 -// RELOCSHARED-NEXT: 0x200F R_386_TLS_TPOFF32 var1 0x0 -// RELOCSHARED-NEXT: 0x2032 R_386_TLS_TPOFF var1 0x0 +// RELOCSHARED-NEXT: 0x1001 R_386_TLS_TPOFF32 var 0x0 +// RELOCSHARED-NEXT: 0x1025 R_386_TLS_TPOFF var 0x0 +// RELOCSHARED-NEXT: 0x100F R_386_TLS_TPOFF32 var1 0x0 +// RELOCSHARED-NEXT: 0x1032 R_386_TLS_TPOFF var1 0x0 // RELOCSHARED-NEXT: } // RELOCSHARED-NEXT: ]