Leonard Grey 58f3c5e696
[lld-macho] Fix thunks for non-__text TEXT sections (#99052)
This supersedes https://github.com/llvm/llvm-project/pull/87818 and
fixes https://github.com/llvm/llvm-project/issues/52767

When calculating arm64 thunks, we make a few assumptions that may not
hold when considering code sections outside of `__text`:

1. That a section needs thunks only if its size is larger than the
branch range.
2. That any calls into `__stubs` are necessarily forward jumps (that is,
the section with the jump is ordered before `__stubs`)

Sections like this exist in the wild, most prominently the
`__lcxx_overrides` section introduced in
https://github.com/llvm/llvm-project/pull/69498

This change:
- Ensures that if one section in `__TEXT` gets thunks, all of them do.
- Makes all code sections in `__TEXT` contiguous (and guaranteed to be
placed before `__stubs`)
2024-07-23 11:02:55 -04:00

56 lines
1.1 KiB
Plaintext

import("//llvm/utils/TableGen/tablegen.gni")
tablegen("Options") {
visibility = [ ":MachO" ]
args = [ "-gen-opt-parser-defs" ]
}
static_library("MachO") {
output_name = "lldMachO"
configs += [ "//llvm/utils/gn/build:lld_code" ]
deps = [
":Options",
"//lld/Common",
"//llvm/lib/BinaryFormat",
"//llvm/lib/Object",
"//llvm/lib/Option",
"//llvm/lib/Support",
"//llvm/lib/Target:TargetsToBuild",
"//llvm/lib/TargetParser",
]
include_dirs = [
".",
"//libunwind/include",
]
sources = [
"Arch/ARM64.cpp",
"Arch/ARM64Common.cpp",
"Arch/ARM64_32.cpp",
"Arch/X86_64.cpp",
"ConcatOutputSection.cpp",
"Driver.cpp",
"DriverUtils.cpp",
"Dwarf.cpp",
"EhFrame.cpp",
"ExportTrie.cpp",
"ICF.cpp",
"InputFiles.cpp",
"InputSection.cpp",
"LTO.cpp",
"MapFile.cpp",
"MarkLive.cpp",
"ObjC.cpp",
"OutputSection.cpp",
"OutputSegment.cpp",
"Relocations.cpp",
"SectionPriorities.cpp",
"Sections.cpp",
"SymbolTable.cpp",
"Symbols.cpp",
"SyntheticSections.cpp",
"Target.cpp",
"UnwindInfoSection.cpp",
"Writer.cpp",
]
}