2015-08-03 10:22:28 +02:00
|
|
|
/** @file
|
|
|
|
|
|
|
|
Unified linker script for GCC based builds
|
|
|
|
|
|
|
|
Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
|
|
|
|
Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
|
2016-07-22 04:56:49 +02:00
|
|
|
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
|
2015-08-03 10:22:28 +02:00
|
|
|
|
|
|
|
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 PECOFF_HEADER_SIZE bytes (which differs
|
|
|
|
* between 32-bit and 64-bit builds). The actual start of the .text section
|
|
|
|
* will be rounded up based on its actual alignment.
|
|
|
|
*/
|
|
|
|
. = PECOFF_HEADER_SIZE;
|
|
|
|
|
|
|
|
.text : ALIGN(CONSTANT(COMMONPAGESIZE)) {
|
|
|
|
*(.text .text.* .stub .gnu.linkonce.t.*)
|
|
|
|
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
|
|
|
*(.got .got.*)
|
2015-08-03 10:22:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The contents of AutoGen.c files are constant from the POV of the program,
|
|
|
|
* but most of its contents end up in .data or .bss by default since few of
|
|
|
|
* the variable definitions that get emitted are declared as CONST.
|
|
|
|
*/
|
|
|
|
*:AutoGen.obj(.data .data.* .bss .bss.*)
|
2015-08-03 10:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-08-03 10:22:39 +02:00
|
|
|
.data ALIGN(ALIGNOF(.text)) : ALIGN(CONSTANT(COMMONPAGESIZE)) {
|
2015-08-03 10:22:28 +02:00
|
|
|
*(.data .data.* .gnu.linkonce.d.*)
|
BaseTools GCC: avoid the use of COMMON symbols
The default behavior of the GCC compiler is to emit uninitialized globals
with external linkage into a COMMON section, where duplicate definitions
are merged. This may result in unexpected behavior, since global variables
defined under the same name in different C files may not refer to the same
logical data item.
For instance, the definitions of EFI_EVENT mVirtualAddressChangeEvent that
[used to] appear in the following files:
CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
will be folded into a single instance of the variable when the latter
module includes the former library, which can lead to unexpected results.
Even if some may argue that there are legal uses for COMMON allocation, the
high modularity of EDK2 combined with the low level of awareness of the
intracicies surrounding common allocation and the generally poor EDK2
developer discipline regarding the use of the STATIC keyword* make a strong
case for disabling it by default, and re-enabling it explicitly for packages
that depend on it.
So prevent GCC from emitting variables into the COMMON section, by passing
-fno-common to the compiler, and discarding the section in the GNU ld linker
script.
* Any function or variable that is only referenced from the translation unit
that defines it could be made STATIC. This does not only prevent issues
like the above, it also allows the compiler to generate better code, e.g.,
drop out of line function definitions after inlining all invocations or
perform constant propagation on variables.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19164 6f19259b-4bc3-4df7-8a09-765794883524
2015-12-08 08:40:12 +01:00
|
|
|
*(.bss .bss.*)
|
2015-08-03 10:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.eh_frame ALIGN(CONSTANT(COMMONPAGESIZE)) : {
|
|
|
|
KEEP (*(.eh_frame))
|
|
|
|
}
|
|
|
|
|
|
|
|
.rela ALIGN(CONSTANT(COMMONPAGESIZE)) : {
|
|
|
|
*(.rela .rela.*)
|
|
|
|
}
|
|
|
|
|
2016-07-22 04:56:49 +02:00
|
|
|
.hii : ALIGN(CONSTANT(COMMONPAGESIZE)) {
|
|
|
|
KEEP (*(.hii))
|
|
|
|
}
|
|
|
|
|
2016-07-27 11:13:58 +02:00
|
|
|
/*
|
|
|
|
* Retain the GNU build id but in a non-allocatable section so GenFw
|
|
|
|
* does not copy it into the PE/COFF image.
|
|
|
|
*/
|
|
|
|
.build-id (INFO) : { *(.note.gnu.build-id) }
|
|
|
|
|
2015-08-03 10:22:28 +02:00
|
|
|
/DISCARD/ : {
|
|
|
|
*(.note.GNU-stack)
|
|
|
|
*(.gnu_debuglink)
|
|
|
|
*(.interp)
|
|
|
|
*(.dynsym)
|
|
|
|
*(.dynstr)
|
|
|
|
*(.dynamic)
|
|
|
|
*(.hash)
|
|
|
|
*(.comment)
|
BaseTools GCC: avoid the use of COMMON symbols
The default behavior of the GCC compiler is to emit uninitialized globals
with external linkage into a COMMON section, where duplicate definitions
are merged. This may result in unexpected behavior, since global variables
defined under the same name in different C files may not refer to the same
logical data item.
For instance, the definitions of EFI_EVENT mVirtualAddressChangeEvent that
[used to] appear in the following files:
CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
will be folded into a single instance of the variable when the latter
module includes the former library, which can lead to unexpected results.
Even if some may argue that there are legal uses for COMMON allocation, the
high modularity of EDK2 combined with the low level of awareness of the
intracicies surrounding common allocation and the generally poor EDK2
developer discipline regarding the use of the STATIC keyword* make a strong
case for disabling it by default, and re-enabling it explicitly for packages
that depend on it.
So prevent GCC from emitting variables into the COMMON section, by passing
-fno-common to the compiler, and discarding the section in the GNU ld linker
script.
* Any function or variable that is only referenced from the translation unit
that defines it could be made STATIC. This does not only prevent issues
like the above, it also allows the compiler to generate better code, e.g.,
drop out of line function definitions after inlining all invocations or
perform constant propagation on variables.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19164 6f19259b-4bc3-4df7-8a09-765794883524
2015-12-08 08:40:12 +01:00
|
|
|
*(COMMON)
|
2015-08-03 10:22:28 +02:00
|
|
|
}
|
|
|
|
}
|