On 22 July 2015 at 21:12, Jordan Justen <[email protected]> wrote:
> On 2015-07-22 06:56:45, Ard Biesheuvel wrote:
>> After two recent changes have been applied to the ELF conversion
>> routines in GenFw, i.e., PE/COFF section alignment based on ELF
>> section alignment (54b1b57a59b5 "BaseTools: Update GenFw to support
>> 4K alignment"), and removal of the debug section (pending), there is
>> no reason anymore to have different GNU ld scripts for GCC/X86 4.4,
>> GCC/X86 4.9 and GCC/AARCH64.
>>
>> So introduce a new unified linker script gcc-base.lds, with overlays
>> to force 4 KB or 64 KB alignment (for building DXE runtime drivers
>> and/or building AARCH64 code using the small C model)
>>
>> Notable differences between the original versions:
>> - the 4 KB alignment linker script is now a simple overlay rather than a
>>   complete duplicate of the original with just the alignment changed;
>
> What do you mean by 'overlay'? Obviously not this:
>
> https://sourceware.org/binutils/docs/ld/Overlay-Description.html#Overlay-Description
>

Nope, sorry, poor choice of words. Let's use 'linker script override',
i.e., a script which just sets some additional parameters, but does
not duplicate the entire original.

> It seems like the new scripts will change GCC44-48 to use 64-byte
> section alignment.
>

Yes, it will. The removal of the .debug section will also reduce the
size of the headers to 0x228, which means that 44-48 and 49 and up
will both start at 0x240, instead of having 0x260 and 0x280,
respectively. So there are up to 3 remaining sections, each of which
may use 32 additional bytes due to rounding; subtract the 0x20 and
0x40 we saved above, and the net result is ~0 on average and 64 bytes
size increase worst case.

What you get in return is identical ELF *and* PE/COFF layouts for all
toolchain versions, which is an improvement imo. But indeed, if you
prefer to keep the rounding for <4.9 exactly as is, another linker
script override could be added for 64 bytes.

> What if we defined two linker script variables via tools def.
>
> GCC:*_*_*_DLINK_LDCFG = $(EDK_TOOLS_PATH)/Scripts/default-cfg.lds
> GCC:*_*_*_DLINK_LDSCRIPT = $(EDK_TOOLS_PATH)/Scripts/default.lds
>
> Then update build_rule to use --script with those two scripts.
>
> It looks like the LDCFG one might be able to set variables, like a
> section_alignment variable that the LDSCRIPT could then use.
>

Unfortunately, the section ALIGN() value that comes /after/ the colon
must be a constant and not an expression. So if that is what we want,
we're down to preprocessor magic or whatever EDK2's equivalent is. But
being able to set a single value rather than using the override
scripts would indeed be quite useful, and I wouldn't mind having
generated linker scripts as build artefacts.

-- 
Ard.


>> - .rodata has been moved into .text where it belongs;
>> - the =90909090 NOP padding has been removed, since the only purpose it
>>   serves is making it easier for hackers to launch exploits, whereas
>>   correct code does not rely on these NOPs at all;
>> - the .got contents have been moved into .text, but since we do not use
>>   PIC code, this input section should always be empty anyway.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel <[email protected]>
>> ---
>>  BaseTools/Scripts/GCC/gcc-align-4K.lds  | 20 +++++++
>>  BaseTools/Scripts/GCC/gcc-align-64K.lds | 20 +++++++
>>  BaseTools/Scripts/GCC/gcc-base.lds      | 62 ++++++++++++++++++++
>>  3 files changed, 102 insertions(+)
>>
>> diff --git a/BaseTools/Scripts/GCC/gcc-align-4K.lds 
>> b/BaseTools/Scripts/GCC/gcc-align-4K.lds
>> new file mode 100644
>> index 000000000000..bba9fc591767
>> --- /dev/null
>> +++ b/BaseTools/Scripts/GCC/gcc-align-4K.lds
>> @@ -0,0 +1,20 @@
>> +/** @file
>> +
>> +  Unified linker script for GCC based builds - 4 KB alignment overlay
>> +
>> +  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials are licensed and made 
>> available under
>> +  the terms and conditions of the BSD License that accompanies this 
>> distribution.
>> +  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php.
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
>> IMPLIED.
>> +
>> +**/
>> +
>> +SECTIONS {
>> +  .text : ALIGN(0x1000) { }
>> +  .data : ALIGN(0x1000) { }
>> +}
>> diff --git a/BaseTools/Scripts/GCC/gcc-align-64K.lds 
>> b/BaseTools/Scripts/GCC/gcc-align-64K.lds
>> new file mode 100644
>> index 000000000000..b115faa8fcbe
>> --- /dev/null
>> +++ b/BaseTools/Scripts/GCC/gcc-align-64K.lds
>> @@ -0,0 +1,20 @@
>> +/** @file
>> +
>> +  Unified linker script for GCC based builds - 64 KB alignment overlay
>> +
>> +  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials are licensed and made 
>> available under
>> +  the terms and conditions of the BSD License that accompanies this 
>> distribution.
>> +  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php.
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
>> IMPLIED.
>> +
>> +**/
>> +
>> +SECTIONS {
>> +  .text : ALIGN(0x10000) { }
>> +  .data : ALIGN(0x10000) { }
>> +}
>> diff --git a/BaseTools/Scripts/GCC/gcc-base.lds 
>> b/BaseTools/Scripts/GCC/gcc-base.lds
>> new file mode 100644
>> index 000000000000..a40640542484
>> --- /dev/null
>> +++ b/BaseTools/Scripts/GCC/gcc-base.lds
>> @@ -0,0 +1,62 @@
>> +/** @file
>> +
>> +  Unified linker script for GCC based builds
>> +
>> +  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials are licensed and made 
>> available under
>> +  the terms and conditions of the BSD License that accompanies this 
>> distribution.
>> +  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php.
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
>> IMPLIED.
>> +
>> +**/
>> +
>> +SECTIONS {
>> +
>> +  /*
>> +   * The PE/COFF binary consists of DOS and PE/COFF headers, and a sequence 
>> of
>> +   * section headers adding up to 0x228 bytes at the most. So choose 0x228 
>> as
>> +   * the start address: the actual start of the .text section will be 
>> rounded
>> +   * up based on its actual alignment.
>> +   */
>> +  . = 0x228;
>> +
>> +  .text : ALIGN(0x40) {
>> +    *(.text .text.* .stub .gnu.linkonce.t.*)
>> +    *(.rodata .rodata.* .gnu.linkonce.r.*)
>> +    *(.got .got.*)
>> +  }
>> +
>> +  /*
>> +   * The alignment of the .data section should be less than or equal to the
>> +   * alignment of the .text section. This ensures that the relative offset
>> +   * between these sections is the same in the ELF and the PE/COFF versions 
>> of
>> +   * this binary.
>> +   */
>> +  .data ALIGN(ALIGNOF(.text)) : {
>> +    *(.data .data.* .gnu.linkonce.d.*)
>> +    *(.bss .bss.* *COM*)
>> +  }
>> +
>> +  .eh_frame ALIGN(0x20) : {
>> +    KEEP (*(.eh_frame))
>> +  }
>> +
>> +  .rela ALIGN(0x20) : {
>> +    *(.rela .rela.*)
>> +  }
>> +
>> +  /DISCARD/ : {
>> +    *(.note.GNU-stack)
>> +    *(.gnu_debuglink)
>> +    *(.interp)
>> +    *(.dynsym)
>> +    *(.dynstr)
>> +    *(.dynamic)
>> +    *(.hash)
>> +    *(.comment)
>> +  }
>> +}
>> --
>> 1.9.1
>>
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to