[PATCH] D156468: [lld-macho] Fixed crashes when linking with incompatible-arch archives/

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 11:24:49 PDT 2023


MaskRay added inline comments.


================
Comment at: lld/MachO/InputFiles.cpp:206
+
+  if (!checkCompatibility(file))
+    return false;
----------------
`return checkCompatibility(file);`


================
Comment at: lld/MachO/InputFiles.cpp:1042
+
+  if (!compatArch)
+    return;
----------------
`if (!compatArch)` cannot be triggered. Delete it.


================
Comment at: lld/MachO/InputFiles.cpp:1044
+    return;
+  if (!(compatArch = compatWithTargetArch(this, hdr)))
+    return;
----------------
`compatArch` seems no longer read after the store. Can `compatArch` be made ArchiveFile specific?


================
Comment at: lld/MachO/InputFiles.cpp:2115
+  // Ignore the I/O error here - will be reported later.
+  if (!err && mbOrErr) {
+    if (identify_magic(mbOrErr->getBuffer()) == file_magic::macho_object) {
----------------
It seems that `if (!mbOrErr)` can be checked first, then use `else if (!err)`


================
Comment at: lld/MachO/InputFiles.cpp:2131
+    if (!mbOrErr)
+      llvm::handleAllErrors(mbOrErr.takeError(),
+                            [](const llvm::ErrorInfoBase &EI) {
----------------
consumeError


================
Comment at: lld/test/MachO/ignore-incompat-arch.s:14
+
+# RUN: llvm-ar r %t/libcallee_arm64.a %t/callee_arm64.o
+# RUN: llvm-ar r %t/libcallee_x86.a %t/callee_x86_64.o
----------------
to prevent a warning from llvm-ar


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156468/new/

https://reviews.llvm.org/D156468



More information about the llvm-commits mailing list