| 1 | //===-- MachOUtils.h - Mach-o specific helpers for dsymutil --------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | #ifndef LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H |
| 9 | #define LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H |
| 10 | |
| 11 | #include "llvm/ADT/StringRef.h" |
| 12 | #include "llvm/Support/FileSystem.h" |
| 13 | #include "llvm/Support/VirtualFileSystem.h" |
| 14 | |
| 15 | #include <string> |
| 16 | |
| 17 | namespace llvm { |
| 18 | class MCStreamer; |
| 19 | class raw_fd_ostream; |
| 20 | namespace dsymutil { |
| 21 | class DebugMap; |
| 22 | struct LinkOptions; |
| 23 | namespace MachOUtils { |
| 24 | |
| 25 | struct ArchAndFile { |
| 26 | std::string Arch; |
| 27 | std::string Path; |
| 28 | int FD = -1; |
| 29 | |
| 30 | llvm::Error createTempFile(); |
| 31 | llvm::StringRef getPath() const; |
| 32 | int getFD() const; |
| 33 | |
| 34 | ArchAndFile(StringRef Arch) : Arch(std::string(Arch)) {} |
| 35 | ArchAndFile(ArchAndFile &&A) = default; |
| 36 | ArchAndFile &operator=(ArchAndFile &&A) = default; |
| 37 | ~ArchAndFile(); |
| 38 | }; |
| 39 | |
| 40 | struct DwarfRelocationApplicationInfo { |
| 41 | // The position in the stream that should be patched, starting from the |
| 42 | // Dwarf's segment file address. |
| 43 | uint64_t AddressFromDwarfStart; |
| 44 | int32_t Value; |
| 45 | // If we should subtract the Dwarf segment's VM address from value before |
| 46 | // writing it. |
| 47 | bool ShouldSubtractDwarfVM; |
| 48 | |
| 49 | DwarfRelocationApplicationInfo(uint64_t AddressFromDwarfVM, uint32_t Value, |
| 50 | bool ShouldSubtractDwarfVM) |
| 51 | : AddressFromDwarfStart(AddressFromDwarfVM), Value(Value), |
| 52 | ShouldSubtractDwarfVM(ShouldSubtractDwarfVM) {} |
| 53 | }; |
| 54 | |
| 55 | bool generateUniversalBinary(SmallVectorImpl<ArchAndFile> &ArchFiles, |
| 56 | StringRef OutputFileName, const LinkOptions &, |
| 57 | StringRef SDKPath, bool Fat64 = false); |
| 58 | bool generateDsymCompanion( |
| 59 | llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, const DebugMap &DM, |
| 60 | MCStreamer &MS, raw_fd_ostream &OutFile, |
| 61 | const std::vector<MachOUtils::DwarfRelocationApplicationInfo> |
| 62 | &RelocationsToApply); |
| 63 | |
| 64 | std::string getArchName(StringRef Arch); |
| 65 | } // namespace MachOUtils |
| 66 | } // namespace dsymutil |
| 67 | } // namespace llvm |
| 68 | #endif // LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H |
| 69 | |