Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage 1 produces debug info that crashes LLDB #12929

Open
topolarity opened this issue Sep 22, 2022 · 12 comments
Open

stage 1 produces debug info that crashes LLDB #12929

topolarity opened this issue Sep 22, 2022 · 12 comments
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. upstream An issue with a third party project that Zig uses.
Milestone

Comments

@topolarity
Copy link
Contributor

Zig Version

0.10.0-dev.4115+75e9a8c7f

Steps to Reproduce

// testme.zig
const std = @import("std");
const Target = std.Target;

pub fn printTargetArch(t: Target) void {
    std.log.err("target: {}", .{ t.cpu.arch });
}

pub fn main() anyerror!void {
    printTargetArch(@import("builtin").target);
}
$ zig build-exe testme.zig -fstage1
$ lldb ./testme
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'lldb.embedded_interpreter'
(lldb) target create "./testme"
Current executable set to '/home/topolarity/repos/zig/testme' (x86_64).
(lldb) br set -f testme.zig -l 5
Breakpoint 1: where = testme`printTargetArch + 8 at testme.zig:5:39, address = 0x0000000000237358
(lldb) r
Process 335621 launched: '/home/topolarity/repos/zig/testme' (x86_64)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
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):
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamEi+0x31)[0x7f30670a5a71]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0xee)[0x7f30670a37be]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0xea5fa6)[0x7f30670a5fa6]
/lib/x86_64-linux-gnu/libc.so.6(+0x3daf0)[0x7f3065a3daf0]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang10ASTContext19getTypeAlignInCharsENS_8QualTypeE+0xb)[0x7f306d71755b]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(+0xe62808)[0x7f306da62808]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(+0xe5eea6)[0x7f306da5eea6]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang10ASTContext18getASTRecordLayoutEPKNS_10RecordDeclE+0x346d)[0x7f306da5a34d]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang10ASTContext18getASTRecordLayoutEPKNS_10RecordDeclE+0x9f6)[0x7f306da578d6]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang10ASTContext18getASTRecordLayoutEPKNS_10RecordDeclE+0x9f6)[0x7f306da578d6]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x959210)[0x7f3070f59210]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x51ba2b)[0x7f3070b1ba2b]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x4598d1)[0x7f3070a598d1]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x458e4b)[0x7f3070a58e4b]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x47a7cf)[0x7f3070a7a7cf]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x425567)[0x7f3070a25567]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x423fb3)[0x7f3070a23fb3]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x423fb3)[0x7f3070a23fb3]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x423d30)[0x7f3070a23d30]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x5a6e75)[0x7f3070ba6e75]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x5a7316)[0x7f3070ba7316]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x5ac72a)[0x7f3070bac72a]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x5ebea3)[0x7f3070bebea3]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x57d4f3)[0x7f3070b7d4f3]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x57c611)[0x7f3070b7c611]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x410280)[0x7f3070a10280]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x410c40)[0x7f3070a10c40]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x410ed6)[0x7f3070a10ed6]
/lib/x86_64-linux-gnu/liblldb-14.so.1(+0x4c9664)[0x7f3070ac9664]
/lib/x86_64-linux-gnu/libc.so.6(+0x87b27)[0x7f3065a87b27]
/lib/x86_64-linux-gnu/libc.so.6(+0x10a78c)[0x7f3065b0a78c]

Expected Behavior

LLDB should not crash.

Actual Behavior

LLDB crashes.

GDB handles this just fine, so this is likely an upstream bug.

@topolarity topolarity added the bug Observed behavior contradicts documented or intended behavior label Sep 22, 2022
@topolarity
Copy link
Contributor Author

Reproduces on Darwin (macOS 12.6) and Linux (Debian Bookworm). Haven't tested other platforms.

@topolarity
Copy link
Contributor Author

Compiling the program with self-hosted instead also leads to poor LLDB behavior:

$ zig build-exe testme.zig         
$ lldb ./testme                              
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'lldb.embedded_interpreter'
(lldb) target create "./testme"
Current executable set to '/home/topolarity/repos/zig/testme' (x86_64).
(lldb) br set -f testme.zig -l 5
Breakpoint 1: where = testme`testme.printTargetArch + 8 at testme.zig:5:16, address = 0x00000000002128f8
(lldb) r
Process 333395 launched: '/home/topolarity/repos/zig/testme' (x86_64)
Process 333395 stopped
* thread #1, name = 'testme', stop reason = breakpoint 1.1
    frame #0: 0x00000000002128f8 testme`testme.printTargetArch at testme.zig:5:16
   2   	const Target = std.Target;
   3   	
   4   	pub fn printTargetArch(t: Target) void {
-> 5   	    std.log.err("target: {}", .{ t.cpu.arch });
   6   	}
   7   	
   8   	pub fn main() anyerror!void {
(lldb) p t
warning: (x86_64) /home/topolarity/repos/zig/testme 0x000002e9: DW_TAG_member bitfield named "payload" has invalid bit offset (0x100000000) member will be ignored. Please file a bug against the compiler and include the preprocessed output for testme
(target.Target) $0 = {
  cpu = {
    model = 0x0000000000201970
    features = {
      ints = ([0] = 17602322383593537648, [1] = 18158514333030456, [2] = 1114271, [3] = 0, [4] = 0)
    }
  }
  os = {
    version_range = {}
  }
}

Notice the missing "payload" field and the corresponding warning.

@topolarity
Copy link
Contributor Author

Does not reproduce with Zig 0.9.1.

As mentioned above, this is likely an upstream bug so I'll see if I can reduce this to some LLVM IR and file upstream.

@topolarity
Copy link
Contributor Author

topolarity commented Sep 22, 2022

Reduced LLVM IR:

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @_start() {
Entry:
  unreachable
}

define internal fastcc void @printTargetArch(ptr %0) !dbg !2251 {
Entry:
  %1 = load i6, ptr null, align 1, !dbg !2258
  store i6 %1, ptr %0, align 1
  ret void
}

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 2, !"Dwarf Version", i32 4}
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "zig 0.10.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !1306)
!3 = !DIFile(filename: "testme", directory: ".")
!4 = !{!96}
!21 = !DIBasicType(name: "u2", size: 2, encoding: DW_ATE_unsigned)
!27 = !DIFile(filename: "target.zig", directory: "/home/topolarity/repos/zig/build/stage3/lib/zig/std")

!96 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "@typeInfo(std.target.Target.Os.VersionRange).Union.tag_type.?", scope: !27, file: !27, line: 225, baseType: !21, size: 8, align: 8, elements: !97)
!97 = !{!98, !99, !100, !101}
!98 = !DIEnumerator(name: "none", value: 0)
!99 = !DIEnumerator(name: "semver", value: 1)
!100 = !DIEnumerator(name: "linux", value: 2)
!101 = !DIEnumerator(name: "windows", value: 3)

!1306 = !{}

!1320 = !DICompositeType(tag: DW_TAG_structure_type, name: "std.target.Target.Os.VersionRange", scope: !27, file: !27, line: 225, size: 320, align: 32, elements: !1321)
!1321 = !{!1322}
!1322 = !DIDerivedType(tag: DW_TAG_member, name: "tag", scope: !1320, file: !27, line: 225, baseType: !96, size: 2, align: 8, offset: 288)

!2251 = distinct !DISubprogram(name: "printTargetArch", scope: !2252, file: !2252, line: 4, type: !2253, scopeLine: 4, flags: DIFlagStaticMember, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !2256)
!2252 = !DIFile(filename: "testme.zig", directory: "/home/topolarity/repos/zig")
!2253 = !DISubroutineType(types: !2254)
!2254 = !{null, !2255}
!2255 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*std.target.Target", baseType: !1320, size: 64, align: 64)
!2256 = !{!2257}
!2257 = !DILocalVariable(name: "t", arg: 1, scope: !2251, file: !2252, line: 4, type: !1320)
!2258 = !DILocation(line: 5, column: 39, scope: !2259)
!2259 = distinct !DILexicalBlock(scope: !2251, file: !2252, line: 4, column: 40)

Reproduce with:

$ llc-15 ./reduced.ll.txt -o ./testme.o -filetype=obj
$ ld.lld-15 -o testme ./testme.o
$ lldb testme -o "br set -f testme.zig -l 5" -o "r"
 -- crashes LLDB

@kamidev
Copy link

kamidev commented Sep 22, 2022

Don't know if this is relevant, but it doesn't reproduce on M1 for me.

➜  zig zig build-exe testme.zig -fstage1
➜  zig ./testme
error: target: std.target.Target.Cpu.Arch.aarch64
➜  zig lldb ./testme
(lldb) target create "./testme"
Current executable set to '/Users/jonas/src/zig/testme' (arm64).
(lldb) ^C
(lldb) ^C
(lldb) ^D
➜  zig sw_vers;clang --version; zig version
ProductName:	macOS
ProductVersion:	12.6
BuildVersion:	21G115
clang version 15.0.1 (dim@tensor.andric.com:git/home-dim.git 285d797c78176dffdea707b28a6dafedf5803ce5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Users/jonas/src/clang+llvm-15.0.1-arm64-apple-darwin21.0/bin
0.10.0-dev.4158+99b954b9c

@kamidev
Copy link

kamidev commented Sep 22, 2022

Doesn't reproduce on Intel Mac, either.

➜  zig zig build-exe testme.zig -fstage1
➜  zig lldb ./testme
(lldb) target create "./testme"
Current executable set to '/Users/jonas/src/zig/testme' (x86_64).
(lldb) ^D
➜  zig sw_vers; clang --version; zig version
ProductName:	macOS
ProductVersion:	12.6
BuildVersion:	21G115
clang version 15.0.1 (https://github.com/tru/llvm-release-build 33b6cbead48e63164b3e7c5ac9d34505c0391552)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Users/jonas/src/clang+llvm-15.0.1-x86_64-apple-darwin/bin
0.10.0-dev.4158+99b954b9c

@topolarity
Copy link
Contributor Author

topolarity commented Sep 22, 2022

Can you try lldb testme -o "br set -f testme.zig -l 6" -o "r"?

The breakpoint + run is required to trigger the crash on my machine

@kamidev
Copy link

kamidev commented Sep 22, 2022

Sorry, read a bit too fast. It doesn't reproduce on my M1 build, though.

➜  zig lldb ./testme
(lldb) target create "./testme"
Current executable set to '/Users/jonas/src/zig/testme' (arm64).
(lldb) br set -f testme.zig -l 5
Breakpoint 1: where = testme`testme.printTargetArch + 44 at testme.zig:6:16, address = 0x0000000100004194
(lldb) r
Process 71196 launched: '/Users/jonas/src/zig/testme' (arm64)
Process 71196 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100004194 testme`testme.printTargetArch at testme.zig:6:16
   3   	const Target = std.Target;
   4
   5   	pub fn printTargetArch(t: Target) void {
-> 6   	    std.log.err("target: {}", .{ t.cpu.arch });
   7   	}
   8
   9   	pub fn main() anyerror!void {
(lldb) p t
(target.Target) $0 = {
  cpu = {
    model = 0x000000010007c018
    features = {
      ints = ([0] = 9220009573262309312, [1] = 4323455646401341088, [2] = 782997792096640, [3] = 0, [4] = 0)
    }
  }
  os = {
    version_range = {
      payload = {
        semver = {
          min = (major = 12, minor = 6, patch = 0)
          max = (major = 12, minor = 6, patch = 0)
        }
        linux = {
          range = {
            min = (major = 12, minor = 6, patch = 0)
            max = (major = 12, minor = 6, patch = 0)
          }
          glibc = (major = 0, minor = 0, patch = 0)
        }
        windows = (min = 12, max = 6)
      }
    }
  }
}

@kamidev
Copy link

kamidev commented Sep 22, 2022

But my Intel build crashes!

➜  zig lldb ./testme
(lldb) target create "./testme"
Current executable set to '/Users/jonas/src/zig/testme' (x86_64).
(lldb) br set -f testme.zig -l 5
Breakpoint 1: where = testme`printTargetArch + 22 at testme.zig:6:39, address = 0x0000000100003276
(lldb) r
Process 75141 launched: '/Users/jonas/src/zig/testme' (x86_64)
PLEASE submit a bug report to https://developer.apple.com/bug-reporting/ and include the crash backtrace.
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):
0  lldb                     0x000000010324c357 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  lldb                     0x000000010324ba85 llvm::sys::RunSignalHandlers() + 85
2  lldb                     0x000000010324ca00 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007ff81e005dfd _sigtramp + 29
4  libsystem_platform.dylib 0x00007fed8b82be00 _sigtramp + 18446744028302172192
5  LLDB                     0x000000011d9a721a (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutField(clang::FieldDecl const*, bool) + 1994
6  LLDB                     0x000000011d9a36e0 (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutFields(clang::RecordDecl const*) + 176
7  LLDB                     0x000000011d99d464 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const + 4532
8  LLDB                     0x000000011d9a31e0 (anonymous namespace)::EmptySubobjectMap::ComputeEmptySubobjectSizes() + 400
9  LLDB                     0x000000011d99c75a clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const + 1194
10 LLDB                     0x000000011d9a31e0 (anonymous namespace)::EmptySubobjectMap::ComputeEmptySubobjectSizes() + 400
11 LLDB                     0x000000011d99c75a clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const + 1194
12 LLDB                     0x0000000119bf45ef lldb_private::TypeSystemClang::GetChildCompilerTypeAtIndex(void*, lldb_private::ExecutionContext*, unsigned long, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, unsigned int&, int&, unsigned int&, unsigned int&, bool&, bool&, lldb_private::ValueObject*, unsigned long long&) + 1231
13 LLDB                     0x00000001197bbf54 lldb_private::CompilerType::GetChildCompilerTypeAtIndex(lldb_private::ExecutionContext*, unsigned long, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, unsigned int&, int&, unsigned int&, unsigned int&, bool&, bool&, lldb_private::ValueObject*, unsigned long long&) const + 100
14 LLDB                     0x00000001196fa8d6 lldb_private::ValueObject::CreateChildAtIndex(unsigned long, bool, int) + 214
15 LLDB                     0x00000001196f9fed lldb_private::ValueObject::GetChildAtIndex(unsigned long, bool) + 317
16 LLDB                     0x0000000119713bee lldb_private::FormatManager::ShouldPrintAsOneLiner(lldb_private::ValueObject&) + 510
17 LLDB                     0x00000001196aa4fd lldb_private::FormatEntity::Format(lldb_private::FormatEntity::Entry const&, lldb_private::Stream&, lldb_private::SymbolContext const*, lldb_private::ExecutionContext const*, lldb_private::Address const*, lldb_private::ValueObject*, bool, bool) + 11277
18 LLDB                     0x00000001196a7d60 lldb_private::FormatEntity::Format(lldb_private::FormatEntity::Entry const&, lldb_private::Stream&, lldb_private::SymbolContext const*, lldb_private::ExecutionContext const*, lldb_private::Address const*, lldb_private::ValueObject*, bool, bool) + 1136
19 LLDB                     0x00000001196a7d60 lldb_private::FormatEntity::Format(lldb_private::FormatEntity::Entry const&, lldb_private::Stream&, lldb_private::SymbolContext const*, lldb_private::ExecutionContext const*, lldb_private::Address const*, lldb_private::ValueObject*, bool, bool) + 1136
20 LLDB                     0x00000001196a7ce1 lldb_private::FormatEntity::Format(lldb_private::FormatEntity::Entry const&, lldb_private::Stream&, lldb_private::SymbolContext const*, lldb_private::ExecutionContext const*, lldb_private::Address const*, lldb_private::ValueObject*, bool, bool) + 1009
21 LLDB                     0x0000000119840d07 lldb_private::StackFrame::DumpUsingSettingsFormat(lldb_private::Stream*, bool, char const*) + 295
22 LLDB                     0x0000000119841189 lldb_private::StackFrame::GetStatus(lldb_private::Stream&, bool, bool, bool, char const*) + 73
23 LLDB                     0x0000000119844e71 lldb_private::StackFrameList::GetStatus(lldb_private::Stream&, unsigned int, unsigned int, bool, unsigned int, bool, char const*) + 433
24 LLDB                     0x00000001198771a4 lldb_private::Thread::GetStatus(lldb_private::Stream&, unsigned int, unsigned int, unsigned int, bool, bool) + 1028
25 LLDB                     0x000000011981656e lldb_private::Process::GetThreadStatus(lldb_private::Stream&, bool, unsigned int, unsigned int, unsigned int, bool) + 430
26 LLDB                     0x0000000119815a41 lldb_private::Process::HandleProcessStateChangedEvent(std::__1::shared_ptr<lldb_private::Event> const&, lldb_private::Stream*, bool&, bool&) + 3793
27 LLDB                     0x000000011969598d lldb_private::Debugger::HandleProcessEvent(std::__1::shared_ptr<lldb_private::Event> const&) + 749
28 LLDB                     0x0000000119696038 lldb_private::Debugger::DefaultEventHandler() + 600
29 LLDB                     0x0000000119696999 lldb_private::Debugger::EventHandlerThread(void*) + 9
30 LLDB                     0x000000011975a146 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) + 118
31 libsystem_pthread.dylib  0x00007ff81dff04e1 _pthread_start + 125
32 libsystem_pthread.dylib  0x00007ff81dfebf6b thread_start + 15
[1]    75138 segmentation fault  lldb ./testme

@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Oct 15, 2022
@andrewrk andrewrk added this to the 0.12.0 milestone Oct 15, 2022
@Vexu
Copy link
Member

Vexu commented Jan 13, 2023

I'm making this the tracking issue for reverting f874b5e

@Vexu Vexu added upstream An issue with a third party project that Zig uses. backend-llvm The LLVM backend outputs an LLVM IR Module. and removed bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Jan 13, 2023
@Vexu Vexu modified the milestones: 0.12.0, 1.0.0 Jan 13, 2023
@kamidev
Copy link

kamidev commented Jan 13, 2023

I just repeated the above LLDB sessions using zig 0.11.0-dev.6038. Both ARM and Intel Macs now work as expected.

@kamidev
Copy link

kamidev commented Jan 13, 2023

This is my current setup (M1 Max):

➜  zig git:(master) sw_vers; clang --version; zig version
ProductName:		macOS
ProductVersion:		13.1
BuildVersion:		22C65
Homebrew clang version 15.0.6
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
0.11.0-dev.6038+d813cef42

Intel MacBook Pro (15-inch, 2018):

➜  zig git:(master) sw_vers; clang --version; zig version
ProductName:	macOS
ProductVersion:	12.6
BuildVersion:	21G115
Homebrew clang version 15.0.6
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
0.11.0-dev.6038+d813cef42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

No branches or pull requests

4 participants