[PATCH] D97610: [lld-macho] check minimum header length when opening linkable input files

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 27 09:22:47 PST 2021


int3 added inline comments.


================
Comment at: lld/MachO/Driver.cpp:264
 
-static InputFile *addFile(StringRef path, bool forceLoadArchive,
-                          bool isBundleLoader = false) {
-  Optional<MemoryBufferRef> buffer = readFile(path);
+static InputFile *addLinkableFile(StringRef path, bool forceLoadArchive,
+                                  bool isBundleLoader = false) {
----------------
petition to keep this as `addFile` -- it's not like we have `addRawFile`, so the additional word seems unnecessary


================
Comment at: lld/MachO/Driver.cpp:407
 
-static void addFileList(StringRef path) {
-  Optional<MemoryBufferRef> buffer = readFile(path);
+static void addFileListFile(StringRef path) {
+  Optional<MemoryBufferRef> buffer = readRawFile(path);
----------------
I think the old name made more sense, we are adding the files in the file list, not the filelist file itself


================
Comment at: lld/test/MachO/invalid/bad-archive.s:9
 # RUN: not %lld %t.o -ObjC %t.a -o /dev/null 2>&1 | FileCheck -DFILE=%t.a %s
-# CHECK: error: [[FILE]]: failed to parse archive: truncated or malformed archive (remaining size of archive too small for next archive member header at offset 8)
+# CHECK: error: file is too small to contain a linkable-file header: [[FILE]]
 
----------------
the original intent of the test was to exercise the archive-parsing code and its error handling, so this is no longer serving its purpose. We could tweak the test, but perhaps it would be easier to just require linkable files to have 4 bytes for the magic number, rather than 20? (plus, I'd like to avoid doing things just because ld64 is doing it, until we find some deeper reason)

similar issue for invalid-fat-narch.s below


================
Comment at: lld/test/MachO/rename.s:17
+# BAD1: lld: error: invalid name for segment or section: -o
+# BAD1: lld: error: file is too small to contain a linkable-file header: /dev/null
+
----------------
we shouldn't be emitting this message if `/dev/null` is an output file parameter


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97610



More information about the llvm-commits mailing list