[llvm] b3e7900 - [llvm-readobj] Exclude Mach-O dylib IDs from needed libraries (#221618)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 03:30:00 PDT 2026
Author: Tianyi Chen
Date: 2026-09-10T11:29:56+01:00
New Revision: b3e7900e74098de130402d0a3ea857e77d817540
URL: https://github.com/llvm/llvm-project/commit/b3e7900e74098de130402d0a3ea857e77d817540
DIFF: https://github.com/llvm/llvm-project/commit/b3e7900e74098de130402d0a3ea857e77d817540.diff
LOG: [llvm-readobj] Exclude Mach-O dylib IDs from needed libraries (#221618)
For Mach-O files, `--needed-libs` includes `LC_ID_DYLIB`, causing a
dynamic
library to list its own install name as a dependency.
Exclude this command while retaining the actual dependency load
commands.
Fixes #39505.
Assisted-by: OpenAI Codex (implementation, tests, and initial
description).
Added:
Modified:
llvm/test/tools/llvm-readobj/MachO/needed-libs.test
llvm/tools/llvm-readobj/MachODumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/MachO/needed-libs.test b/llvm/test/tools/llvm-readobj/MachO/needed-libs.test
index e97e490dbb075..75de64b338da1 100644
--- a/llvm/test/tools/llvm-readobj/MachO/needed-libs.test
+++ b/llvm/test/tools/llvm-readobj/MachO/needed-libs.test
@@ -1,8 +1,13 @@
+## LC_ID_DYLIB names the library itself, not a dependency.
# RUN: yaml2obj %s -o %t.o
# RUN: llvm-readobj --needed-libs %t.o | FileCheck %s
# CHECK: NeededLibraries [
+# CHECK-NEXT: /usr/lib/libLazy.dylib
+# CHECK-NEXT: /usr/lib/libReexport.dylib
# CHECK-NEXT: /usr/lib/libSystem.B.dylib
+# CHECK-NEXT: /usr/lib/libUpward.dylib
+# CHECK-NEXT: /usr/lib/libWeak.dylib
# CHECK-NEXT: ]
!mach-o
@@ -10,12 +15,20 @@ FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
- filetype: 0x00000001
- ncmds: 1
- sizeofcmds: 56
+ filetype: 0x00000006
+ ncmds: 6
+ sizeofcmds: 336
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
+ - cmd: LC_ID_DYLIB
+ cmdsize: 56
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 81985536
+ compatibility_version: 65536
+ Content: /usr/lib/libSelf.dylib
- cmd: LC_LOAD_DYLIB
cmdsize: 56
dylib:
@@ -24,3 +37,35 @@ LoadCommands:
current_version: 81985536
compatibility_version: 65536
Content: /usr/lib/libSystem.B.dylib
+ - cmd: LC_LOAD_WEAK_DYLIB
+ cmdsize: 56
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 81985536
+ compatibility_version: 65536
+ Content: /usr/lib/libWeak.dylib
+ - cmd: LC_REEXPORT_DYLIB
+ cmdsize: 56
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 81985536
+ compatibility_version: 65536
+ Content: /usr/lib/libReexport.dylib
+ - cmd: LC_LAZY_LOAD_DYLIB
+ cmdsize: 56
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 81985536
+ compatibility_version: 65536
+ Content: /usr/lib/libLazy.dylib
+ - cmd: LC_LOAD_UPWARD_DYLIB
+ cmdsize: 56
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 81985536
+ compatibility_version: 65536
+ Content: /usr/lib/libUpward.dylib
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index 8fc92850606af..5a0bcf040b304 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -826,7 +826,6 @@ void MachODumper::printNeededLibraries() {
for (const auto &Command : Obj->load_commands()) {
if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
- Command.C.cmd == MachO::LC_ID_DYLIB ||
Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
Command.C.cmd == MachO::LC_REEXPORT_DYLIB ||
Command.C.cmd == MachO::LC_LAZY_LOAD_DYLIB ||
More information about the llvm-commits
mailing list