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
|
|
|
|
|
|
|
/*
|
BaseTools: GCC: move most AutoGen.obj contents back to .data section
The generated AutoGen.c files mostly contain read-only data, but due to
lacking annotations, all of it is emitted into the .data section by the
compiler.
Given that GUIDs are UEFI's gaffer tape, having writable GUIDs is a
security hazard, and this was the main rationale for putting AutoGen.obj
in the .text section. However, as it turns out, patchable PCDs are emitted
there as well, which can legally be modified at runtime.
So update the wildcard pattern to only match g...Guid sections, and move
everything else back to .data (Note that this relies on -fdata-sections,
without that option, everything is emitted into .data)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Fixes: 233bd25b000f92fc4bbe181fa48edcd72808de8e
[lersek@redhat.com: add reference to previous commit being fixed up]
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
2017-02-23 19:30:51 +01:00
|
|
|
* The contents of AutoGen.c files are mostly constant from the POV of the
|
|
|
|
* program, but most of it ends up in .data or .bss by default since few of
|
2015-08-03 10:22:50 +02:00
|
|
|
* the variable definitions that get emitted are declared as CONST.
|
BaseTools: GCC: move most AutoGen.obj contents back to .data section
The generated AutoGen.c files mostly contain read-only data, but due to
lacking annotations, all of it is emitted into the .data section by the
compiler.
Given that GUIDs are UEFI's gaffer tape, having writable GUIDs is a
security hazard, and this was the main rationale for putting AutoGen.obj
in the .text section. However, as it turns out, patchable PCDs are emitted
there as well, which can legally be modified at runtime.
So update the wildcard pattern to only match g...Guid sections, and move
everything else back to .data (Note that this relies on -fdata-sections,
without that option, everything is emitted into .data)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Fixes: 233bd25b000f92fc4bbe181fa48edcd72808de8e
[lersek@redhat.com: add reference to previous commit being fixed up]
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
2017-02-23 19:30:51 +01:00
|
|
|
* Unfortunately, we cannot pull it into the .text section entirely, since
|
|
|
|
* patchable PCDs are also emitted here, but we can at least move all of the
|
|
|
|
* emitted GUIDs here.
|
2015-08-03 10:22:50 +02:00
|
|
|
*/
|
BaseTools: GCC: move most AutoGen.obj contents back to .data section
The generated AutoGen.c files mostly contain read-only data, but due to
lacking annotations, all of it is emitted into the .data section by the
compiler.
Given that GUIDs are UEFI's gaffer tape, having writable GUIDs is a
security hazard, and this was the main rationale for putting AutoGen.obj
in the .text section. However, as it turns out, patchable PCDs are emitted
there as well, which can legally be modified at runtime.
So update the wildcard pattern to only match g...Guid sections, and move
everything else back to .data (Note that this relies on -fdata-sections,
without that option, everything is emitted into .data)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Fixes: 233bd25b000f92fc4bbe181fa48edcd72808de8e
[lersek@redhat.com: add reference to previous commit being fixed up]
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
2017-02-23 19:30:51 +01:00
|
|
|
*:AutoGen.obj(.data.g*Guid)
|
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))
|
|
|
|
}
|
|
|
|
|
2016-08-10 10:55:30 +02:00
|
|
|
.rela (INFO) : {
|
2015-08-03 10:22:28 +02:00
|
|
|
*(.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
|
|
|
}
|
|
|
|
}
|