]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools RVCT: use scatter file to enforce minimum section alignment
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 14 Dec 2015 07:55:46 +0000 (07:55 +0000)
committerabiesheuvel <abiesheuvel@Edk2>
Mon, 14 Dec 2015 07:55:46 +0000 (07:55 +0000)
Up until SVN r18540, GenFw created invalid PE/COFF binaries for the ARM
architecture, by allowing PE/COFF .data sections to appear at offsets
that were not aligned to the global PE/COFF section alignment. The
reason for this was that the relocation metadata emitted by RVCT's
armlink only contains dynamic absolute relocations, so it is impossible
to recalculate relative relocations between .text and .data, and so the
relative offset between the two needs to be preserved.

Since r18540, we do align .data to the PE/COFF section alignment,
resulting in potentially corrupt PE/COFF binaries unless .data happens
to appear at a 32-byte aligned offset. So let's introduce a RVCT scatter
file that sets this alignment for the ELF .data section (and subsequent
.bss section).

At the same time, set the start offset to 0x220 bytes (which is the size
of our 32-bit PE/COFF header) so that the memory layouts are identical
between ELF and PE/COFF. Also add a 4 KB aligned version that can be
used to build DXE_RUNTIME_DRIVER modules with runtime memory protection
enabled.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Eugene Cohen <eugene@hp.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19235 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Conf/tools_def.template
BaseTools/Scripts/Rvct-Align32.sct [new file with mode: 0644]
BaseTools/Scripts/Rvct-Align4K.sct [new file with mode: 0644]

index 1a44fbd1d3ebbb00a53df3d7d7f83cc0c341f69d..fc79bd660142e2c96408cb14909d7bd825ae6395 100644 (file)
@@ -7128,7 +7128,7 @@ RELEASE_XCODE5_X64_CC_FLAGS   = -target x86_64-pc-win32-macho -c    -Os       -W
 \r
 DEFINE RVCT_ALL_ASM_FLAGS   = --diag_suppress=1786 --diag_error=warning --apcs /interwork\r
 DEFINE RVCT_ALL_CC_FLAGS    = --c90 -c --no_autoinline --asm --gnu --apcs /interwork --signed_chars --no_unaligned_access --split_sections --enum_is_int --preinclude AutoGen.h --diag_suppress=186 --diag_warning 167 --diag_error=warning --diag_style=ide --protect_stack\r
-DEFINE RVCT_ALL_DLINK_FLAGS = --ro-base 0 --no_scanlib --reloc --no_exceptions --datacompressor off --strict --symbols --diag_style=ide --no_legacyalign\r
+DEFINE RVCT_ALL_DLINK_FLAGS = --no_scanlib --no_exceptions --datacompressor off --strict --symbols --diag_style=ide --no_legacyalign --scatter $(EDK_TOOLS_PATH)/Scripts/Rvct-Align32.sct\r
 \r
 ####################################################################################\r
 #\r
diff --git a/BaseTools/Scripts/Rvct-Align32.sct b/BaseTools/Scripts/Rvct-Align32.sct
new file mode 100644 (file)
index 0000000..4f29ad4
--- /dev/null
@@ -0,0 +1,25 @@
+/** @file\r
+\r
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+REGION 0x220 RELOC {\r
+  ER_RO +0 ALIGN 32 {\r
+    * (+RO)\r
+  }\r
+  ER_RW +0 ALIGN 32 {\r
+    * (+RW)\r
+  }\r
+  ER_ZI +0 {\r
+    * (+ZI)\r
+  }\r
+}\r
diff --git a/BaseTools/Scripts/Rvct-Align4K.sct b/BaseTools/Scripts/Rvct-Align4K.sct
new file mode 100644 (file)
index 0000000..83f5a0d
--- /dev/null
@@ -0,0 +1,25 @@
+/** @file\r
+\r
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+REGION 0x1000 RELOC {\r
+  ER_RO +0 ALIGN 4096 {\r
+    * (+RO)\r
+  }\r
+  ER_RW +0 ALIGN 4096 {\r
+    * (+RW)\r
+  }\r
+  ER_ZI +0 {\r
+    * (+ZI)\r
+  }\r
+}\r