> On Dec 7, 2015, at 3:45 AM, Shi, Steven <[email protected]> wrote:
>
> Hello,
> I'm working on enabling the standard clang3.7 build for MinnowMax open source
> firmware. I meet an warning when use GNU ld linker to generate X64 image:
> "ld: warning: section `.data' type changed to PROGBITS" as below. This
> warning only appears on X64 binaries linking, and not on the i32 binaries
> linking.
>
> "ld" -o
> /mnt/disk3/mnw2opensrc/Build/Vlv2TbltDevicePkg/DEBUG_CLANG37/X64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> -nostdlib -n -q --gc-sections
> --script=/mnt/disk3/mnw2opensrc/BaseTools/Scripts/gcc4.4-ld-script --entry
> _ModuleEntryPoint -u _ModuleEntryPoint -Map
> /mnt/disk3/mnw2opensrc/Build/Vlv2TbltDevicePkg/DEBUG_CLANG37/X64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.map
> -melf_x86_64 --oformat=elf64-x86-64 -pie --start-group
> @/mnt/disk3/mnw2opensrc/Build/Vlv2TbltDevicePkg/DEBUG_CLANG37/X64/MdeModulePkg/Core/Dxe/DxeMain/OUTPUT/static_library_files.lst
> --end-group
> ld: warning: section `.data' type changed to PROGBITS
>
> Then, I find all the static global variables (e.g. Protocol Guids) in the
> .data section of X64 binary become zero or random values during runtime, and
> the firmware fail to boot in DXE, but the ia32 PEI works well. How could I
> let ld don't change the .data section of X64 binary? Has anyone tried the
> EDK2 build with standard clang compiler? I appreciate if someone could let me
> know the workable clang build options. Thanks in advance.
>
>
Steven,
I use clang, but with the Xcode linker on a Mac.
It looks like globals do get put in the __DATA,__data. So that is the __DATA
segment, with the __data section. An uninitialized global variable goes in
__DATA, __common. I would expect __DATA,__data to have values, and
uninitialized variables to be zero.
My guess is the linker script has some kind of assumption in it that is not
valid for clang?
You can play around with -S to see what the default compiler behavior is:
~/work/Compiler>cat g.c
#include <stdio.h>
char *One = "-I";
const char *Two = "";
char *Three;
~/work/Compiler>clang -Os -S g.c
~/work/Compiler>cat g.S
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 11
.section __TEXT,__cstring,cstring_literals
L_.str: ## @.str
.asciz "-I"
.section __DATA,__data
.globl _One ## @One
.align 3
_One:
.quad L_.str
.section __TEXT,__cstring,cstring_literals
L_.str1: ## @.str1
.space 1
.section __DATA,__data
.globl _Two ## @Two
.align 3
_Two:
.quad L_.str1
.comm _Three,8,3 ## @Three
.subsections_via_symbols
Thanks,
Andrew Fish
>
>
> Below is my current build tools version and related build options:
> clang version 3.7.0 (tags/RELEASE_370/final)
> GNU ld (GNU Binutils for Ubuntu) 2.25.1
> GNU ar (GNU Binutils for Ubuntu) 2.25.1
> gcc-4.8 (Ubuntu 4.8.5-1ubuntu1) 4.8.5
>
> *_CLANG37_X64_OBJCOPY_PATH = DEF(GCC48_X64_PREFIX)objcopy
> *_CLANG37_X64_CC_PATH = DEF(CLANG37_X64_PREFIX)clang-3.7
> *_CLANG37_X64_SLINK_PATH = DEF(GCC48_X64_PREFIX)ar
> *_CLANG37_X64_DLINK_PATH = DEF(GCC48_X64_PREFIX)ld
> *_CLANG37_X64_ASLDLINK_PATH = DEF(GCC48_X64_PREFIX)ld
> *_CLANG37_X64_ASM_PATH = DEF(GCC48_X64_PREFIX)gcc-4.8
> *_CLANG37_X64_PP_PATH = DEF(CLANG37_X64_PREFIX)clang-3.7
> *_CLANG37_X64_VFRPP_PATH = DEF(CLANG37_X64_PREFIX)clang-3.7
> *_CLANG37_X64_ASLCC_PATH = DEF(CLANG37_X64_PREFIX)clang-3.7
> *_CLANG37_X64_ASLPP_PATH = DEF(CLANG37_X64_PREFIX)clang-3.7
> *_CLANG37_X64_RC_PATH = DEF(GCC48_X64_PREFIX)objcopy
>
> DEFINE CLANG37_ALL_CC_FLAGS = -c -g -fshort-wchar
> -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -Wno-address
> -Wno-shift-negative-value -Wno-empty-body -Wno-parentheses-equality
> -Wno-unknown-pragmas -Wno-enum-conversion -nostdlib -fno-builtin
> -ffreestanding -nostdinc -Wno-tautological-constant-out-of-range-compare
> -ffunction-sections -fdata-sections -include AutoGen.h
> -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -fno-stack-protector
> DEFINE CLANG37_X64_CC_FLAGS = DEF(CLANG37_ALL_CC_FLAGS) -m64 -O0
> -v --target=x86_64 "-DEFIAPI=__attribute__((ms_abi))" -DNO_BUILTIN_VA_FUNCS
> -mno-red-zone -Wno-address -mcmodel=large -fno-asynchronous-unwind-tables -D
> EFI32 -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -fasm-blocks
> -mms-bitfields -msoft-float
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang
>
> *_CLANG37_X64_CC_FLAGS = DEF(CLANG37_X64_CC_FLAGS)
> *_CLANG37_X64_DLINK_FLAGS = DEF(GCC48_X64_DLINK_FLAGS) -pie
>
> Steven Shi
> SSG\STO\UEFI Firmware
>
> Tel: +86 021-61166522
> iNet: 821-6522
>
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel