[Bug ld/20062] New: Gold2.26 fail to link Uefi firmware with internal error in do_layout, but ld works

2016-05-08 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20062

Bug ID: 20062
   Summary: Gold2.26 fail to link Uefi firmware with internal
error in do_layout, but ld works
   Product: binutils
   Version: 2.26
Status: NEW
  Severity: critical
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: steven.shi at intel dot com
  Target Milestone: ---

Created attachment 9242
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9242&action=edit
Uefi hello example with pre-built libraires to link

Uefi standard (http://www.uefi.org/) firmware
(https://github.com/tianocore/edk2) can build with ld, but cannot build with
gold linker. When link a uefi module, the gold will report internal error in
do_layout as blew.

ld-new: internal error in do_layout, at ../../binutils-2.26/gold/object.cc:1819

Attachment is a Uefi hello example with pre-built libraires, you can direclty
extract it and link them with ld and ld-new:

gold 2.26 will fail as below:
"ld-new" -o Hello.dll -nostdlib -n -q --gc-sections -z common-page-size=0x40
--entry _ModuleEntryPoint -u _ModuleEntryPoint -Map Hello.map -melf_x86_64
--oformat=elf64-x86-64 --start-group  @static_library_files.lst --end-group
--defsym=PECOFF_HEADER_SIZE=0x228 --script=GccBase.lds
ld-new: internal error in do_layout, at ../../binutils-2.26/gold/object.cc:1819


but ld 2.26 will succeed:
"ld" -o Hello.dll -nostdlib -n -q --gc-sections -z common-page-size=0x40
--entry _ModuleEntryPoint -u _ModuleEntryPoint -Map Hello.map -melf_x86_64
--oformat=elf64-x86-64 --start-group  @static_library_files.lst --end-group
--defsym=PECOFF_HEADER_SIZE=0x228 --script=GccBase.lds

BTW, this folder example libraries are abstracted from Uefi Hello module build
as below. If you need, you can build them by yourself
1. Setup EDK2 build environment as steps in the link:
https://github.com/tianocore/tianocore.github.io/wiki/Using-EDK-II-with-Native-GCC
 
2. git clone https://github.com/tianocore/edk2 (e.g. ~/edk2)
3. cd ~/edk2
4. make -C BaseTools
5. source edksetup.sh
6. build -t GCC49 -a X64 -p AppPkg/AppPkg.dsc -m
AppPkg/Applications/Hello/Hello.inf

After build, you can find all intermediate files in below folder
~/edk2/Build/AppPkg/DEBUG_GCC49/X64/AppPkg/Applications/Hello/Hello

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/20070] New: LLVM gold plugin(LLVMgold.so) report Unexpected resolution failure on ld when LTO, but pass on gold

2016-05-10 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20070

Bug ID: 20070
   Summary: LLVM gold plugin(LLVMgold.so) report Unexpected
resolution failure on ld when LTO, but pass on gold
   Product: binutils
   Version: 2.26
Status: NEW
  Severity: critical
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: steven.shi at intel dot com
  Target Milestone: ---

Created attachment 9249
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9249&action=edit
testcase to reproduce LLVMgold.so Unexpected resolution failure on ld

I'm enabling clang LTO feature to to improve code size of Uefi standard
(http://www.uefi.org/) firmware (https://github.com/tianocore/edk2). My project
is in https://github.com/shijunjing/edk2 branch llvm :
https://github.com/shijunjing/edk2/tree/llvm.

I find ld in binutils 2.26 cannot co-work correctly with LLVM gold plugin
(LLVMgold.so), and the LLVM gold plugin will report unexpected resolution
failure as below when ld do the optimization. But this failure will not happen
on gold.

Unexpected resolution
UNREACHABLE executed at
/home/jshi19/llvm-3.8.0.src/tools/gold/gold-plugin.cpp:679!


Below is the steps on how to setup clang compiler and reproduce the clang LTO
link failure:

1. Download and extract the llvm 3.8.0 Pre-Built Binaries from
http://www.llvm.org/releases/ (e.g.
http://www.llvm.org/releases/3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
and extract it as ~/clang38).
2. Decompress and rename the debug version LLVM gold plugin in
https://github.com/shijunjing/edk2/blob/llvm/BaseTools/Bin/LLVMgold-debug.tar.gz
as LLVMgold.so. Copy it to above clang lib folder (e.g.
~/clang38/lib/LLVMgold.so)
3. Copy GNU Binutils 2.26 linker ld to /usr/bin/ld
4. run below clang LTO link command:

~/clang38/bin/clang -o Hello.dll -flto -nostdlib -Wl,-n -Wl,-q
-Wl,--gc-sections -Wl,-z,common-page-size=0x40 -Wl,--entry,_ModuleEntryPoint
-Wl,-u,_ModuleEntryPoint -Wl,-Map,Hello.map -Wl,-melf_x86_64
-Wl,--oformat=elf64-x86-64 -Wl,--start-group,,@static_library_files.lst
-Wl,--end-group

ld 2.26 fail in gold plugin optimization with below output:
steven: getModuleForFile pass
Unexpected resolution
UNREACHABLE executed at
/home/jshi19/llvm-3.8.0.src/tools/gold/gold-plugin.cpp:679!
clang-3.8: error: unable to execute command: Aborted (core dumped)
clang-3.8: error: linker command failed due to signal (use -v to see
invocation)

5. Copy GNU Binutils 2.26 gold linker ld-new to /usr/bin/ld
6. re-run step 4 clang LTO link command again:

~/clang38/bin/clang -o Hello.dll -flto -nostdlib -Wl,-n -Wl,-q
-Wl,--gc-sections -Wl,-z,common-page-size=0x40 -Wl,--entry,_ModuleEntryPoint
-Wl,-u,_ModuleEntryPoint -Wl,-Map,Hello.map -Wl,-melf_x86_64
-Wl,--oformat=elf64-x86-64 -Wl,--start-group,,@static_library_files.lst
-Wl,--end-group


gold pass gold plugin optimization with below output:
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
steven: getModuleForFile pass
/usr/bin/ld: internal error in do_layout, at
../../binutils-2.26/gold/object.cc:1819
clang-3.8: error: linker command failed with exit code 1 (use -v to see
invocation)
Above gold do_layout issue is a known bug which is not related LLVM LTO, and
has been tracked in Bug 20062
https://sourceware.org/bugzilla/show_bug.cgi?id=20062

The "steven: getModuleForFile pass" is debug message I especially added in the
debug version LLVMgold.so, which is line 905 in
llvm-3.8.0.src\tools\gold\gold-plugin.cpp. I have a gold-plugin.cpp copy in
this folder.



This folder example libraries are abstracted from Uefi Hello module. You can
build them by yourself from https://github.com/shijunjing/edk2/tree/llvm

0. Download and extract the llvm 3.8.0 Pre-Built Binaries from
http://www.llvm.org/releases/ (e.g.
http://www.llvm.org/releases/3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
and extract it as ~/clang38).
0. Decompress and rename the debug version LLVM gold plugin in
https://github.com/shijunjing/edk2/blob/llvm/BaseTools/Bin/LLVMgold-debug.tar.gz
as LLVMgold.so. Copy it to above clang lib folder (e.g.
~/clang38/lib/LLVMgold.so)
1. Setup EDK2 build environment as steps in the link:
https://github.com/tianocore/tianocore.githu

[Bug gold/20062] Gold2.26 fail to link Uefi firmware with internal error in do_layout, but ld works

2016-05-11 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20062

Steven Shi  changed:

   What|Removed |Added

 CC||steven.shi at intel dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/20070] LLVM gold plugin(LLVMgold.so) report Unexpected resolution failure on ld when LTO, but pass on gold

2016-05-11 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20070

--- Comment #2 from Steven Shi  ---
Hi H.J.
Your patch works for me. Thank you!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug gold/20062] Gold2.26 fail to link Uefi firmware with internal error in do_layout, but ld works

2016-05-14 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20062

--- Comment #1 from Steven Shi  ---
Hello,
How's the issue going on? Please let me know if you need other more
information. Thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/20070] LLVM gold plugin(LLVMgold.so) report Unexpected resolution failure on ld when LTO, but pass on gold

2016-05-16 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20070

Steven Shi  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|FIXED   |---

--- Comment #6 from Steven Shi  ---
Hello,
You know I’m debugging and I hope to disable all optimizations in the LTO
firstly, then enable them one by one later. But when I try to disable the
optimization by enforcing –O0 in the LTO build, I find the ld fails to
recognize some clang  bitcode library, and fail to link. 

e.g. use the Clang_LTO_Fails_On_LD example in below bug attachment
https://sourceware.org/bugzilla/show_bug.cgi?id=20070

If I enforce the –O0 to disable the optimization in LTO, the ld fail to link:
~/clang38/bin/clang -o Hello.dll -flto -O0 -nostdlib -Wl,-n -Wl,-q
-Wl,--gc-sections -Wl,-z,common-page-size=0x40 -Wl,--entry,_ModuleEntryPoint
-Wl,-u,_ModuleEntryPoint -Wl,-Map,Hello.map -Wl,-melf_x86_64
-Wl,--oformat=elf64-x86-64 -Wl,--start-group,,@static_library_files.lst
-Wl,--end-group
BaseLib.lib: error adding symbols: File format not recognized
clang-3.8: error: linker command failed with exit code 1 (use -v to see
invocation)

But if I enable the –O1,  the ld  link pass:
~/clang38/bin/clang -o Hello.dll -flto –O1 -nostdlib -Wl,-n -Wl,-q
-Wl,--gc-sections -Wl,-z,common-page-size=0x40 -Wl,--entry,_ModuleEntryPoint
-Wl,-u,_ModuleEntryPoint -Wl,-Map,Hello.map -Wl,-melf_x86_64
-Wl,--oformat=elf64-x86-64 -Wl,--start-group,,@static_library_files.lst
-Wl,--end-group

So, I cannot correctly disable the the optimization in ld LTO. Please help to
fix it. Thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/20070] LLVM gold plugin(LLVMgold.so) report Unexpected resolution failure on ld when LTO, but pass on gold

2016-05-16 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20070

--- Comment #8 from Steven Shi  ---
Hi H.J.
Thank you for the quick fix. How can I know what different optimization used by
the ld between -O0 and -O1? Is the compiler domain optimization (e.g.
clang/llvm) or the linker (e.g. ld) domain optimization make the difference?
How can I enable or disable these specific optimization besides using -O0 or
-O1?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/20070] LLVM gold plugin(LLVMgold.so) report Unexpected resolution failure on ld when LTO, but pass on gold

2016-05-18 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20070

--- Comment #10 from Steven Shi  ---
LLVM guys say "LTO is linker specific, clang is only forwarding the option to
the linker here." see below discussion about "How to debug if LTO generate
wrong code?":
http://lists.llvm.org/pipermail/cfe-dev/2016-May/048906.html

So it looks, if I compile my llvm bitcode without any optimization level (-O0)
and pass them to linker to finish the LTO build, all the optimizations are done
only by the linker, not llvm.

Is it right?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug gold/20062] Gold2.26 fail to link Uefi firmware with internal error in do_layout, but ld works

2016-05-18 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20062

--- Comment #2 from Steven Shi  ---
Hello,
I'm sorry, but how's the issue going on? I really hope to try the gold linker
for my LTO build.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug gold/20062] Gold2.26 fail to link Uefi firmware with internal error in do_layout, but ld works

2017-12-11 Thread steven.shi at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=20062

--- Comment #4 from Steven Shi  ---
Thanks. With below build option update, the Uefi GCC5 tool chain can use
ld.gold  build OVMF and boot on Qemu.

$ git diff master
diff --git a/BaseTools/Conf/tools_def.template
b/BaseTools/Conf/tools_def.template
index 98ab6dd..919c1b4 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4584,14 +4584,14 @@ DEFINE GCC48_AARCH64_DLINK2_FLAGS=
DEF(GCC47_AARCH64_DLINK2_FLAGS)
 DEFINE GCC48_ARM_ASLDLINK_FLAGS  = DEF(GCC47_ARM_ASLDLINK_FLAGS)
 DEFINE GCC48_AARCH64_ASLDLINK_FLAGS  = DEF(GCC47_AARCH64_ASLDLINK_FLAGS)

-DEFINE GCC49_IA32_CC_FLAGS   = DEF(GCC48_IA32_CC_FLAGS)
-DEFINE GCC49_X64_CC_FLAGS= DEF(GCC48_X64_CC_FLAGS)
+DEFINE GCC49_IA32_CC_FLAGS   = DEF(GCC48_IA32_CC_FLAGS) -fuse-ld=gold
+DEFINE GCC49_X64_CC_FLAGS= DEF(GCC48_X64_CC_FLAGS) -fuse-ld=gold
-mcmodel=large -fno-pie
 DEFINE GCC49_IA32_X64_DLINK_COMMON   = -nostdlib -Wl,-n,-q,--gc-sections -z
common-page-size=0x40
 DEFINE GCC49_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON)
-Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
 DEFINE GCC49_IA32_X64_DLINK_FLAGS= DEF(GCC49_IA32_X64_DLINK_COMMON)
-Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT)
-Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
-DEFINE GCC49_IA32_DLINK2_FLAGS   = DEF(GCC48_IA32_DLINK2_FLAGS)
+DEFINE GCC49_IA32_DLINK2_FLAGS   = DEF(GCC48_IA32_DLINK2_FLAGS)
-fuse-ld=gold -Wl,--no-gc-sections
 DEFINE GCC49_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS)
-Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie
-DEFINE GCC49_X64_DLINK2_FLAGS= DEF(GCC48_X64_DLINK2_FLAGS)
+DEFINE GCC49_X64_DLINK2_FLAGS= DEF(GCC48_X64_DLINK2_FLAGS)
-fuse-ld=gold -Wl,-no-pie,--no-gc-sections
 DEFINE GCC49_ASM_FLAGS   = DEF(GCC48_ASM_FLAGS)
 DEFINE GCC49_ARM_ASM_FLAGS   = DEF(GCC48_ARM_ASM_FLAGS)
 DEFINE GCC49_AARCH64_ASM_FLAGS   = DEF(GCC48_AARCH64_ASM_FLAGS)
diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds
old mode 100644
new mode 100755
index a43e007..7e2f5a7
--- a/BaseTools/Scripts/GccBase.lds
+++ b/BaseTools/Scripts/GccBase.lds
@@ -57,10 +57,6 @@ SECTIONS {
 KEEP (*(.eh_frame))
   }

-  .rela (INFO) : {
-*(.rela .rela.*)
-  }
-
   .hii : ALIGN(CONSTANT(COMMONPAGESIZE)) {
 KEEP (*(.hii))
   }
@@ -69,7 +65,6 @@ SECTIONS {
* 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) }

   /DISCARD/ : {
 *(.note.GNU-stack)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils