[lld-macho] Fix loading same libraries from both LC_LINKER_OPTION and command line
authorKaining Zhong <zhongkaining.paxos@bytedance.com>
Tue, 19 Jul 2022 21:43:30 +0000 (17:43 -0400)
committerJez Ng <jezng@fb.com>
Tue, 19 Jul 2022 21:46:14 +0000 (17:46 -0400)
commitdd5635541cd7bbd62cd59b6694dfb759b6e9a0d8
tree9e4e712c22bcbe1ab4a21ef3c6b799c1b521f3a2
parentd2c0572b2efef6c71d13bb579ac50f2d3dd8e76e
[lld-macho] Fix loading same libraries from both LC_LINKER_OPTION and command line

This fixes https://github.com/llvm/llvm-project/issues/56059 and
https://github.com/llvm/llvm-project/issues/56440. This is inspired by
tapthaker's patch (https://reviews.llvm.org/D127941), and has reused his
test cases. This patch adds an bool "isCommandLineLoad" to indicate
where archives are from. If lld tries to load the same library loaded
previously by LC_LINKER_OPTION from CLI, it will use this
isCommandLineLoad to determine if it should be affected by -all_load &
-ObjC flags. This also prevents -force_load from affecting archives
loaded previously from CLI without such flag, whereas tapthaker's patch
will fail such test case (introduced by
https://reviews.llvm.org/D128025).

Reviewed By: int3, #lld-macho

Differential Revision: https://reviews.llvm.org/D129556
lld/MachO/Driver.cpp
lld/test/MachO/lc-linker-option.ll