facebookarchive / BOLT

Binary Optimization and Layout Tool - A linux command-line utility used for optimizing performance of binaries
2.51k stars 177 forks source link

clang14 build with -update-debug-sections rewrite debug info core #307

Closed zpget closed 1 year ago

zpget commented 1 year ago

compiler: clang14, default dwarf5 error msg: BOLT-INFO: SCTC: patched 39 tail calls (36 forward) tail calls (3 backward) from a total of 39 while removing 0 double jumps and removing 28 basic blocks totalling 140 bytes of code. CTCs total execution count is 70740640 and the number of times CTCs are taken is 0. BOLT-INFO: padding code to 0xb800000 to accommodate hot text BOLT-WARNING: empty location list detected at 0x27 for DIE at 0x490b in CU at 0x53d BOLT-WARNING: unexpected low_pc form value. Cannot update DIE at offset 0x491f BOLT-WARNING: Unsupported DWARFLocationEntry Kind:5 Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it): PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump:

  1. Program arguments: llvm-bolt -enable-bat=1 test -o test.bolt -data test.fdata -align-macro-fusion=all -reorder-blocks=cache+ -reorder-functions=hfsort+ -split-functions=3 -split-all-cold -split-eh -dyno-stats -icf=1 -update-debug-sections
aaupov commented 1 year ago

Hi @zpget,

Thanks for reporting! Can you please also include full backtrace and the version of BOLT used? It would also be helpful for us to be able to repro the build - if clang14 binary is built manually, what's the CMake command line? If it's distro built, which package is it?

@ayermolo - does that look familiar? Can that be the cause of the crash?

BOLT-WARNING: Unsupported DWARFLocationEntry Kind:5

zpget commented 1 year ago

Hi @zpget,

Thanks for reporting! Can you please also include full backtrace and the version of BOLT used? It would also be helpful for us to be able to repro the build - if clang14 binary is built manually, what's the CMake command line? If it's distro built, which package is it?

@ayermolo - does that look familiar? Can that be the cause of the crash?

BOLT-WARNING: Unsupported DWARFLocationEntry Kind:5

  1. bolt version: llvm-project-llvmorg-14.0.0 release
  2. core line: bolt/lib/Rewrite/DWARFRewriter.cpp switch (Entry.Kind) { default: llvm_unreachable("Unsupported DWARFLocationEntry Kind.");

Kind:5

  1. binary code is complex , main module depend on many other modules(static link)
aaupov commented 1 year ago

I would suggest you check if the issue reproduces with the trunk version of BOLT first. AFAIK DWARF5 support was added to BOLT after LLVM14 release and it wasn't backported.

ayermolo commented 1 year ago

Hi I am currently on PTO so won't be able to look until next week, but does sound like you are using BOLT version that doesn't support DWARF5. Please try with trunk as Amir suggested.

zpget commented 1 year ago

BOLT version: BOLT-INFO: BOLT version: 56ff67ccd90702d87a44c7e60abe3c4986855493 with latest trunk, still has core switch (Entry.Kind) { default: errs() << "BOLT-WARNING: Unsupported DWARFLocationEntry Kind. type=" << std::to_string(Entry.Kind) << '\n'; llvm_unreachable("Unsupported DWARFLocationEntry Kind."); i add log errs() << "BOLT-WARNING: Unsupported DWARFLocationEntry Kind. type=" << std::to_string(Entry.Kind) << '\n'; and coredump before get: BOLT-WARNING: Unsupported DWARFLocationEntry Kind. type=5

before coredump print so many warnings: BOLT-WARNING: empty location list detected at 0x6dd5 for DIE at 0x1779b0 in CU at 0x215b0 BOLT-WARNING: unexpected low_pc form value. Cannot update DIE at offset 0x1779c2 BOLT-WARNING: empty location list detected at 0x6dd7 for DIE at 0x1779d2 in CU at 0x215b0 BOLT-WARNING: unexpected low_pc form value. Cannot update DIE at offset 0x1779db BOLT-WARNING: unexpected low_pc form value. Cannot update DIE at offset 0x1779ff BOLT-WARNING: unexpected low_pc form value. Cannot update DIE at offset 0x177a23

zpget commented 1 year ago

clang build with -gdwarf-4 -gstrict-dwarf , BOLT-WARNING: Unsupported DWARFLocationEntry Kind. type=8 add @@ -516,6 +518,12 @@ void DWARFRewriter::updateUnitDebugInfo( BaseAddress + Entry.Value0, BaseAddress + Entry.Value1, Entry.Loc}); break;

can success , but has warning BOLT-WARNING: empty location list detected at 0x6dd8 for DIE at 0x177aa4 in CU at 0x215b0 and gdb load bin has no debug info warning GNU gdb (GDB) 11.2 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: https://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/.

For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from test.bolt... DW_FORM_strp pointing outside of .debug_str section [in module /home/work/test.bolt] (No debugging symbols found in test.bolt)

so something wrong with debuginfo update?

aaupov commented 1 year ago

BOLT version: BOLT-INFO: BOLT version: 56ff67c with latest trunk, still has core

You're using non-upstreamed BOLT version which was last updated in Jan this year. BOLT has been part of LLVM monorepo since then: https://github.com/llvm/llvm-project/tree/main/bolt

Please follow the instructions on that page (https://github.com/llvm/llvm-project/tree/main/bolt#manual-build) to check out and build the latest trunk version.

zpget commented 1 year ago

ok, now can fix coredump ,but get some ERROR: BOLT-ERROR: unsupported form for DW_AT_call_return_pc

ayermolo commented 1 year ago

Hmm. Are you sure you are on latest llvm trunk? I am pretty sure I fixed that and committed it.

zpget commented 1 year ago

with this commit: 4f158995b9cddae392bfb5989af8c83101ae0789 https://github.com/llvm/llvm-project/commit/4f158995b9cddae392bfb5989af8c83101ae0789

today i see have a latest commit? 4d3a0cade2ed0bdc87256c197215691c2e279ed0 i need try again?

ayermolo commented 1 year ago

I added support in https://reviews.llvm.org/D128526 Maybe I missed a case. Can you provide a binary and/or how it was build?

zpget commented 1 year ago

compiler: llvm-project-14.0.5.src/clang f68d4e64a17b5699e0245b1a7c445830d38fd75f demo: simple main demo

include

include

include

include

int LOOPS=1000; void test() { for (int i = 0; i < LOOPS; i++ ) { std::string tmp = "hello" + std::to_string(i); std::cout << tmp << std::endl; } }

int main() { while (true) { test(); sleep(5); } return 0; } compile cmd: clang-14/bin/clang++ main.cpp -std=c++11 -Wl,-q demo bin: a.out.zip errmsg: BOLT-INFO: padding code to 0xa00000 to accommodate hot text BOLT-ERROR: unsupported form for DW_AT_call_return_pc Function:__libc_csu_init for DIE.dump() 0x00000696: DW_TAG_call_site DW_AT_call_return_pc (0x00000000004016dc)

ayermolo commented 1 year ago

Debug Info in question comes from GCC compiled code. https://reviews.llvm.org/D136204

zpget commented 1 year ago

Debug Info in question comes from GCC compiled code. https://reviews.llvm.org/D136204

ok, test can work, thanks~