[lld] c4053cd - [lld/mac] Don't crash on -order_file with assembly inputs on arm64

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri May 28 18:00:57 PDT 2021


Author: Nico Weber
Date: 2021-05-28T21:00:46-04:00
New Revision: c4053cd14eb9b5fe12b4ea9bc99bd83548d1f371

URL: https://github.com/llvm/llvm-project/commit/c4053cd14eb9b5fe12b4ea9bc99bd83548d1f371
DIFF: https://github.com/llvm/llvm-project/commit/c4053cd14eb9b5fe12b4ea9bc99bd83548d1f371.diff

LOG: [lld/mac] Don't crash on -order_file with assembly inputs on arm64

.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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index aa5f60ff57d0..fc5f239d6f9e 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -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);
   }
 

diff  --git a/lld/test/MachO/order-file.s b/lld/test/MachO/order-file.s
index 63dfca1d8f63..d0efefcb0feb 100644
--- a/lld/test/MachO/order-file.s
+++ b/lld/test/MachO/order-file.s
@@ -172,3 +172,7 @@ _bar:
 _main:
   callq "-[Foo doFoo:andBar:]"
   ret
+
+.section  __DWARF,__debug_aranges,regular,debug
+ltmp1:
+  .byte 0


        


More information about the llvm-commits mailing list