public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] BaseTools/GCC ARM/AARCH64: Force disable PIE
@ 2017-05-24 20:26 dann frazier
  2017-05-24 22:27 ` Ard Biesheuvel
  0 siblings, 1 reply; 4+ messages in thread
From: dann frazier @ 2017-05-24 20:26 UTC (permalink / raw)
  To: Ard Biesheuvel, Leif Lindholm; +Cc: Yonghong Zhu, Liming Gao, edk2-devel

v2:
* Replace -no-pie w/ -static for compat with GCC 4.9

After Debian's toolchain switched to PIE by default, our edk2 builds began
to fail to build (GCC49 w/ gcc 6.3). This patch fixes the build by forcing
off PIE for both ARM and AARCH64 builds.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: dann frazier <dannf@debian.org>
---
 BaseTools/Conf/tools_def.template | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 4b1b7b548c..fc0bf2ff70 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4339,14 +4339,14 @@ DEFINE GCC_ALL_CC_FLAGS            = -g -Os -fshort-wchar -fno-builtin -fno-stri
 DEFINE GCC_IA32_CC_FLAGS           = DEF(GCC_ALL_CC_FLAGS) -m32 -malign-double -freorder-blocks -freorder-blocks-and-partition -O2 -mno-stack-arg-probe
 DEFINE GCC_X64_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mno-red-zone -Wno-address -mno-stack-arg-probe
 DEFINE GCC_IPF_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -minline-int-divide-min-latency
-DEFINE GCC_ARM_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wno-address -mthumb -mfloat-abi=soft
+DEFINE GCC_ARM_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wno-address -mthumb -mfloat-abi=soft -fno-pie
 DEFINE GCC_ARM_CC_XIPFLAGS         = -mno-unaligned-access
-DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -Wno-address -fno-asynchronous-unwind-tables -fno-pic
+DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -Wno-address -fno-asynchronous-unwind-tables -fno-pic -fno-pie
 DEFINE GCC_AARCH64_CC_XIPFLAGS     = -mstrict-align
 DEFINE GCC_DLINK_FLAGS_COMMON      = -nostdlib --pie
 DEFINE GCC_DLINK2_FLAGS_COMMON     = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
 DEFINE GCC_IA32_X64_DLINK_COMMON   = DEF(GCC_DLINK_FLAGS_COMMON) --gc-sections
-DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
+DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -static -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
 DEFINE GCC_ARM_DLINK_FLAGS         = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
 DEFINE GCC_AARCH64_DLINK_FLAGS     = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
 DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] BaseTools/GCC ARM/AARCH64: Force disable PIE
  2017-05-24 20:26 [PATCH v2] BaseTools/GCC ARM/AARCH64: Force disable PIE dann frazier
@ 2017-05-24 22:27 ` Ard Biesheuvel
  2017-05-25 21:24   ` dann frazier
  0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2017-05-24 22:27 UTC (permalink / raw)
  To: dann frazier
  Cc: Leif Lindholm, Yonghong Zhu, Liming Gao, edk2-devel@lists.01.org

On 24 May 2017 at 13:26, dann frazier <dannf@debian.org> wrote:
> v2:
> * Replace -no-pie w/ -static for compat with GCC 4.9
>

For my understanding, could you elaborate on what goes wrong if you
omit -static / -no-pie?

> After Debian's toolchain switched to PIE by default, our edk2 builds began
> to fail to build (GCC49 w/ gcc 6.3). This patch fixes the build by forcing
> off PIE for both ARM and AARCH64 builds.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: dann frazier <dannf@debian.org>
> ---
>  BaseTools/Conf/tools_def.template | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
> index 4b1b7b548c..fc0bf2ff70 100755
> --- a/BaseTools/Conf/tools_def.template
> +++ b/BaseTools/Conf/tools_def.template
> @@ -4339,14 +4339,14 @@ DEFINE GCC_ALL_CC_FLAGS            = -g -Os -fshort-wchar -fno-builtin -fno-stri
>  DEFINE GCC_IA32_CC_FLAGS           = DEF(GCC_ALL_CC_FLAGS) -m32 -malign-double -freorder-blocks -freorder-blocks-and-partition -O2 -mno-stack-arg-probe
>  DEFINE GCC_X64_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mno-red-zone -Wno-address -mno-stack-arg-probe
>  DEFINE GCC_IPF_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -minline-int-divide-min-latency
> -DEFINE GCC_ARM_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wno-address -mthumb -mfloat-abi=soft
> +DEFINE GCC_ARM_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wno-address -mthumb -mfloat-abi=soft -fno-pie
>  DEFINE GCC_ARM_CC_XIPFLAGS         = -mno-unaligned-access
> -DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -Wno-address -fno-asynchronous-unwind-tables -fno-pic
> +DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -Wno-address -fno-asynchronous-unwind-tables -fno-pic -fno-pie
>  DEFINE GCC_AARCH64_CC_XIPFLAGS     = -mstrict-align
>  DEFINE GCC_DLINK_FLAGS_COMMON      = -nostdlib --pie
>  DEFINE GCC_DLINK2_FLAGS_COMMON     = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
>  DEFINE GCC_IA32_X64_DLINK_COMMON   = DEF(GCC_DLINK_FLAGS_COMMON) --gc-sections
> -DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
> +DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -static -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
>  DEFINE GCC_ARM_DLINK_FLAGS         = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
>  DEFINE GCC_AARCH64_DLINK_FLAGS     = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
>  DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
> --
> 2.11.0
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] BaseTools/GCC ARM/AARCH64: Force disable PIE
  2017-05-24 22:27 ` Ard Biesheuvel
@ 2017-05-25 21:24   ` dann frazier
  2017-05-28 12:14     ` Ard Biesheuvel
  0 siblings, 1 reply; 4+ messages in thread
From: dann frazier @ 2017-05-25 21:24 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Leif Lindholm, Yonghong Zhu, Liming Gao, edk2-devel@lists.01.org

On Wed, May 24, 2017 at 03:27:07PM -0700, Ard Biesheuvel wrote:
> On 24 May 2017 at 13:26, dann frazier <dannf@debian.org> wrote:
> > v2:
> > * Replace -no-pie w/ -static for compat with GCC 4.9
> >
> 
> For my understanding, could you elaborate on what goes wrong if you
> omit -static / -no-pie?

Well, nothing... now :) -static/-no-pie was avoiding an issue with GenFw:

   -----------
"GenFw" -e SEC -o /tmp/edk2/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.efi /tmp/edk2/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll
GenFw: ERROR 3000: Invalid
  WriteSections64():
  /tmp/edk2/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll
  AARCH64 small code model requires identical ELF and PE/COFF section
  offsets modulo 4 KB.
[...]
   -----------

Upon rebase/retest, I found that this was no longer reproducible.
Bisection shows that the problem went away recently after this commit:

commit 00b00cc57bfe0fca54c904d4dd44a263e243c88b
Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Date:   Fri May 19 11:47:40 2017 +0100

    BaseTools/Scripts: discard .gnu.hash section in GCC builds

-*f*no-pie does still seem to be needed though. Without it, the ARM
build fails with:

   -----------
"GenFw" -e DXE_DRIVER -o /tmp/edk2/Build/ArmVirtQemu-ARM/DEBUG_GCC49/ARM/MdeModulePkg/Universal/Network/DpcDxe/DpcDxe/DEBUG/DpcDxe.efi /tmp/edk2/Build/ArmVirtQemu-ARM/DEBUG_GCC49/ARM/MdeModulePkg/Universal/Network/DpcDxe/DpcDxe/DEBUG/DpcDxe.dll
GenFw: ERROR 3000: Invalid
  /tmp/edk2/Build/ArmVirtQemu-ARM/DEBUG_GCC49/ARM/MdeModulePkg/Universal/Network/DpcDxe/DpcDxe/DEBUG/DpcDxe.dll: Bad definition for symbol '_GLOBAL_OFFSET_TABLE_'@0x5e94 or unsupported symbol type.  For example, absolute and undefined symbols are not supported.
   -----------

  -dann


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] BaseTools/GCC ARM/AARCH64: Force disable PIE
  2017-05-25 21:24   ` dann frazier
@ 2017-05-28 12:14     ` Ard Biesheuvel
  0 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2017-05-28 12:14 UTC (permalink / raw)
  To: dann frazier
  Cc: Leif Lindholm, Yonghong Zhu, Liming Gao, edk2-devel@lists.01.org

On 25 May 2017 at 21:24, dann frazier <dannf@debian.org> wrote:
> On Wed, May 24, 2017 at 03:27:07PM -0700, Ard Biesheuvel wrote:
>> On 24 May 2017 at 13:26, dann frazier <dannf@debian.org> wrote:
>> > v2:
>> > * Replace -no-pie w/ -static for compat with GCC 4.9
>> >
>>
>> For my understanding, could you elaborate on what goes wrong if you
>> omit -static / -no-pie?
>
> Well, nothing... now :) -static/-no-pie was avoiding an issue with GenFw:
>
>    -----------
> "GenFw" -e SEC -o /tmp/edk2/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.efi /tmp/edk2/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll
> GenFw: ERROR 3000: Invalid
>   WriteSections64():
>   /tmp/edk2/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll
>   AARCH64 small code model requires identical ELF and PE/COFF section
>   offsets modulo 4 KB.
> [...]
>    -----------
>
> Upon rebase/retest, I found that this was no longer reproducible.
> Bisection shows that the problem went away recently after this commit:
>
> commit 00b00cc57bfe0fca54c904d4dd44a263e243c88b
> Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Date:   Fri May 19 11:47:40 2017 +0100
>
>     BaseTools/Scripts: discard .gnu.hash section in GCC builds
>
> -*f*no-pie does still seem to be needed though. Without it, the ARM
> build fails with:
>
>    -----------
> "GenFw" -e DXE_DRIVER -o /tmp/edk2/Build/ArmVirtQemu-ARM/DEBUG_GCC49/ARM/MdeModulePkg/Universal/Network/DpcDxe/DpcDxe/DEBUG/DpcDxe.efi /tmp/edk2/Build/ArmVirtQemu-ARM/DEBUG_GCC49/ARM/MdeModulePkg/Universal/Network/DpcDxe/DpcDxe/DEBUG/DpcDxe.dll
> GenFw: ERROR 3000: Invalid
>   /tmp/edk2/Build/ArmVirtQemu-ARM/DEBUG_GCC49/ARM/MdeModulePkg/Universal/Network/DpcDxe/DpcDxe/DEBUG/DpcDxe.dll: Bad definition for symbol '_GLOBAL_OFFSET_TABLE_'@0x5e94 or unsupported symbol type.  For example, absolute and undefined symbols are not supported.
>    -----------
>

Meh. That is actually quite annoying. For AARCH64, we simply haven't
implemented the GOT related ELF relocations in the ELF to PE/COFF
converter, so there we cannot deal with PIC code involving GOT entries
at all. For ARM, the only roadblock appears to be that
__GLOBAL_OFFSET_TABLE__ is emitted as SHN_ABS (which makes no sense at
all given that it points into the image, which makes it relative like
any other symbol reference).

In any case, could you please drop the -static and respin? Thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-28 12:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24 20:26 [PATCH v2] BaseTools/GCC ARM/AARCH64: Force disable PIE dann frazier
2017-05-24 22:27 ` Ard Biesheuvel
2017-05-25 21:24   ` dann frazier
2017-05-28 12:14     ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox