[lld/mac] Don't crash on -order_file with assembly inputs on arm64
authorNico Weber <thakis@chromium.org>
Sat, 29 May 2021 00:37:39 +0000 (20:37 -0400)
committerNico Weber <thakis@chromium.org>
Sat, 29 May 2021 01:00:46 +0000 (21:00 -0400)
.s files with `-g` generate __debug_aranges on darwin/arm64 for some
reason, and those lead to `nullptr` symbols. Don't crash on that.

Fixes PR50517.

Differential Revision: https://reviews.llvm.org/D103350

lld/MachO/Writer.cpp
lld/test/MachO/order-file.s

index aa5f60f..fc5f239 100644 (file)
@@ -748,7 +748,7 @@ static DenseMap<const InputSection *, size_t> buildInputSectionPriorities() {
   for (const InputFile *file : inputFiles) {
     if (isa<ObjFile>(file))
       for (Symbol *sym : file->symbols)
-        if (auto *d = dyn_cast<Defined>(sym))
+        if (auto *d = dyn_cast_or_null<Defined>(sym))
           addSym(*d);
   }
 
index 63dfca1..d0efefc 100644 (file)
@@ -172,3 +172,7 @@ _bar:
 _main:
   callq "-[Foo doFoo:andBar:]"
   ret
+
+.section  __DWARF,__debug_aranges,regular,debug
+ltmp1:
+  .byte 0