elf2efi: ensure minimum gap between .text and other sections
authorLuca Boccassi <bluca@debian.org>
Tue, 23 May 2023 01:12:12 +0000 (02:12 +0100)
committerLuca Boccassi <bluca@debian.org>
Wed, 24 May 2023 10:06:36 +0000 (11:06 +0100)
When linking an almost empty binary the linker can merged .text with
a later section, creating a RWE segment, that then it rejects.

tools/elf2efi.lds

index 805efc156d14886b4cf0313aee124960efe30d85..6e9eff0763af51947c7abf7467cd92953eb6e524 100644 (file)
@@ -6,6 +6,13 @@ SECTIONS {
         .text ALIGN(CONSTANT(MAXPAGESIZE)) : {
                 *(.text .text.*)
         }
+
+        /* When linking a minimal addon stub, the linker can merge .text and .dynsym, creating a RWE
+         * segment, and then rejects it. Ensure there's a gap so that we end up with two separate segments.
+         * The alignments for the next sections are only applied if the section exists, so they are not
+         * enough, and we need to have this unconditional one. */
+        . = ALIGN(CONSTANT(MAXPAGESIZE));
+
         .rodata ALIGN(CONSTANT(MAXPAGESIZE)) : {
                 *(.rodata .rodata.*)
                 *(.srodata .srodata.*)