Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 1 | //===- ELFObjcopy.cpp -----------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "ELFObjcopy.h" |
| 10 | #include "Buffer.h" |
| 11 | #include "CopyConfig.h" |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 12 | #include "Object.h" |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 13 | #include "llvm-objcopy.h" |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 14 | |
| 15 | #include "llvm/ADT/BitmaskEnum.h" |
| 16 | #include "llvm/ADT/Optional.h" |
| 17 | #include "llvm/ADT/STLExtras.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/ADT/StringRef.h" |
| 20 | #include "llvm/ADT/Twine.h" |
| 21 | #include "llvm/BinaryFormat/ELF.h" |
| 22 | #include "llvm/MC/MCTargetOptions.h" |
| 23 | #include "llvm/Object/Binary.h" |
| 24 | #include "llvm/Object/ELFObjectFile.h" |
| 25 | #include "llvm/Object/ELFTypes.h" |
| 26 | #include "llvm/Object/Error.h" |
| 27 | #include "llvm/Option/Option.h" |
| 28 | #include "llvm/Support/Casting.h" |
| 29 | #include "llvm/Support/Compression.h" |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Errc.h" |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Error.h" |
| 32 | #include "llvm/Support/ErrorHandling.h" |
| 33 | #include "llvm/Support/ErrorOr.h" |
| 34 | #include "llvm/Support/Memory.h" |
| 35 | #include "llvm/Support/Path.h" |
| 36 | #include "llvm/Support/raw_ostream.h" |
| 37 | #include <algorithm> |
| 38 | #include <cassert> |
| 39 | #include <cstdlib> |
| 40 | #include <functional> |
| 41 | #include <iterator> |
| 42 | #include <memory> |
| 43 | #include <string> |
| 44 | #include <system_error> |
| 45 | #include <utility> |
| 46 | |
| 47 | namespace llvm { |
| 48 | namespace objcopy { |
| 49 | namespace elf { |
| 50 | |
| 51 | using namespace object; |
| 52 | using namespace ELF; |
| 53 | using SectionPred = std::function<bool(const SectionBase &Sec)>; |
| 54 | |
| 55 | static bool isDebugSection(const SectionBase &Sec) { |
| 56 | return StringRef(Sec.Name).startswith(".debug") || |
| 57 | StringRef(Sec.Name).startswith(".zdebug") || Sec.Name == ".gdb_index"; |
| 58 | } |
| 59 | |
| 60 | static bool isDWOSection(const SectionBase &Sec) { |
| 61 | return StringRef(Sec.Name).endswith(".dwo"); |
| 62 | } |
| 63 | |
| 64 | static bool onlyKeepDWOPred(const Object &Obj, const SectionBase &Sec) { |
| 65 | // We can't remove the section header string table. |
| 66 | if (&Sec == Obj.SectionNames) |
| 67 | return false; |
| 68 | // Short of keeping the string table we want to keep everything that is a DWO |
| 69 | // section and remove everything else. |
| 70 | return !isDWOSection(Sec); |
| 71 | } |
| 72 | |
Jordan Rupprecht | c892741 | 2019-01-29 15:05:38 +0000 | [diff] [blame] | 73 | static uint64_t setSectionFlagsPreserveMask(uint64_t OldFlags, |
| 74 | uint64_t NewFlags) { |
| 75 | // Preserve some flags which should not be dropped when setting flags. |
| 76 | // Also, preserve anything OS/processor dependant. |
| 77 | const uint64_t PreserveMask = ELF::SHF_COMPRESSED | ELF::SHF_EXCLUDE | |
| 78 | ELF::SHF_GROUP | ELF::SHF_LINK_ORDER | |
| 79 | ELF::SHF_MASKOS | ELF::SHF_MASKPROC | |
| 80 | ELF::SHF_TLS | ELF::SHF_INFO_LINK; |
| 81 | return (OldFlags & PreserveMask) | (NewFlags & ~PreserveMask); |
| 82 | } |
| 83 | |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 84 | static ElfType getOutputElfType(const Binary &Bin) { |
| 85 | // Infer output ELF type from the input ELF object |
| 86 | if (isa<ELFObjectFile<ELF32LE>>(Bin)) |
| 87 | return ELFT_ELF32LE; |
| 88 | if (isa<ELFObjectFile<ELF64LE>>(Bin)) |
| 89 | return ELFT_ELF64LE; |
| 90 | if (isa<ELFObjectFile<ELF32BE>>(Bin)) |
| 91 | return ELFT_ELF32BE; |
| 92 | if (isa<ELFObjectFile<ELF64BE>>(Bin)) |
| 93 | return ELFT_ELF64BE; |
| 94 | llvm_unreachable("Invalid ELFType"); |
| 95 | } |
| 96 | |
| 97 | static ElfType getOutputElfType(const MachineInfo &MI) { |
| 98 | // Infer output ELF type from the binary arch specified |
| 99 | if (MI.Is64Bit) |
| 100 | return MI.IsLittleEndian ? ELFT_ELF64LE : ELFT_ELF64BE; |
| 101 | else |
| 102 | return MI.IsLittleEndian ? ELFT_ELF32LE : ELFT_ELF32BE; |
| 103 | } |
| 104 | |
| 105 | static std::unique_ptr<Writer> createWriter(const CopyConfig &Config, |
| 106 | Object &Obj, Buffer &Buf, |
| 107 | ElfType OutputElfType) { |
| 108 | if (Config.OutputFormat == "binary") { |
| 109 | return llvm::make_unique<BinaryWriter>(Obj, Buf); |
| 110 | } |
| 111 | // Depending on the initial ELFT and OutputFormat we need a different Writer. |
| 112 | switch (OutputElfType) { |
| 113 | case ELFT_ELF32LE: |
| 114 | return llvm::make_unique<ELFWriter<ELF32LE>>(Obj, Buf, |
| 115 | !Config.StripSections); |
| 116 | case ELFT_ELF64LE: |
| 117 | return llvm::make_unique<ELFWriter<ELF64LE>>(Obj, Buf, |
| 118 | !Config.StripSections); |
| 119 | case ELFT_ELF32BE: |
| 120 | return llvm::make_unique<ELFWriter<ELF32BE>>(Obj, Buf, |
| 121 | !Config.StripSections); |
| 122 | case ELFT_ELF64BE: |
| 123 | return llvm::make_unique<ELFWriter<ELF64BE>>(Obj, Buf, |
| 124 | !Config.StripSections); |
| 125 | } |
| 126 | llvm_unreachable("Invalid output format"); |
| 127 | } |
| 128 | |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 129 | template <class ELFT> |
| 130 | static Expected<ArrayRef<uint8_t>> |
| 131 | findBuildID(const object::ELFFile<ELFT> &In) { |
| 132 | for (const auto &Phdr : unwrapOrError(In.program_headers())) { |
| 133 | if (Phdr.p_type != PT_NOTE) |
| 134 | continue; |
| 135 | Error Err = Error::success(); |
David Blaikie | ba005aa | 2018-12-11 00:09:06 +0000 | [diff] [blame] | 136 | for (const auto &Note : In.notes(Phdr, Err)) |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 137 | if (Note.getType() == NT_GNU_BUILD_ID && Note.getName() == ELF_NOTE_GNU) |
| 138 | return Note.getDesc(); |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 139 | if (Err) |
| 140 | return std::move(Err); |
| 141 | } |
| 142 | return createStringError(llvm::errc::invalid_argument, |
| 143 | "Could not find build ID."); |
| 144 | } |
| 145 | |
| 146 | static Expected<ArrayRef<uint8_t>> |
| 147 | findBuildID(const object::ELFObjectFileBase &In) { |
| 148 | if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(&In)) |
| 149 | return findBuildID(*O->getELFFile()); |
| 150 | else if (auto *O = dyn_cast<ELFObjectFile<ELF64LE>>(&In)) |
| 151 | return findBuildID(*O->getELFFile()); |
| 152 | else if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(&In)) |
| 153 | return findBuildID(*O->getELFFile()); |
| 154 | else if (auto *O = dyn_cast<ELFObjectFile<ELF64BE>>(&In)) |
| 155 | return findBuildID(*O->getELFFile()); |
| 156 | |
| 157 | llvm_unreachable("Bad file format"); |
| 158 | } |
| 159 | |
Jake Ehrlich | 5049c34 | 2019-03-18 20:35:18 +0000 | [diff] [blame] | 160 | template <class... Ts> |
| 161 | static Error makeStringError(std::error_code EC, const Twine &Msg, Ts&&... Args) { |
| 162 | std::string FullMsg = (EC.message() + ": " + Msg).str(); |
| 163 | return createStringError(EC, FullMsg.c_str(), std::forward<Ts>(Args)...); |
| 164 | } |
| 165 | |
| 166 | #define MODEL_8 "%%%%%%%%" |
| 167 | #define MODEL_16 MODEL_8 MODEL_8 |
| 168 | #define MODEL_32 (MODEL_16 MODEL_16) |
| 169 | |
Jordan Rupprecht | fc832e9 | 2019-01-30 18:13:30 +0000 | [diff] [blame] | 170 | static Error linkToBuildIdDir(const CopyConfig &Config, StringRef ToLink, |
| 171 | StringRef Suffix, |
| 172 | ArrayRef<uint8_t> BuildIdBytes) { |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 173 | SmallString<128> Path = Config.BuildIdLinkDir; |
| 174 | sys::path::append(Path, llvm::toHex(BuildIdBytes[0], /*LowerCase*/ true)); |
| 175 | if (auto EC = sys::fs::create_directories(Path)) |
Jordan Rupprecht | fc832e9 | 2019-01-30 18:13:30 +0000 | [diff] [blame] | 176 | return createFileError( |
| 177 | Path.str(), |
Jake Ehrlich | 5049c34 | 2019-03-18 20:35:18 +0000 | [diff] [blame] | 178 | makeStringError(EC, "cannot create build ID link directory")); |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 179 | |
| 180 | sys::path::append(Path, |
| 181 | llvm::toHex(BuildIdBytes.slice(1), /*LowerCase*/ true)); |
| 182 | Path += Suffix; |
Jake Ehrlich | 5049c34 | 2019-03-18 20:35:18 +0000 | [diff] [blame] | 183 | SmallString<128> TmpPath; |
| 184 | // create_hard_link races so we need to link to a temporary path but |
| 185 | // we want to make sure that we choose a filename that does not exist. |
| 186 | // By using 32 model characters we get 128-bits of entropy. It is |
| 187 | // unlikely that this string has ever existed before much less exists |
| 188 | // on this disk or in the current working directory. |
| 189 | // Additionally we prepend the original Path for debugging but also |
| 190 | // because it ensures that we're linking within a directory on the same |
| 191 | // partition on the same device which is critical. It has the added |
| 192 | // win of yet further decreasing the odds of a conflict. |
| 193 | sys::fs::createUniquePath(Twine(Path) + "-" + MODEL_32 + ".tmp", TmpPath, |
| 194 | /*MakeAbsolute*/ false); |
| 195 | if (auto EC = sys::fs::create_hard_link(ToLink, TmpPath)) { |
| 196 | Path.push_back('\0'); |
| 197 | return makeStringError(EC, "cannot link %s to %s", ToLink.data(), |
| 198 | Path.data()); |
| 199 | } |
| 200 | // We then atomically rename the link into place which will just move the |
| 201 | // link. If rename fails something is more seriously wrong so just return |
| 202 | // an error. |
| 203 | if (auto EC = sys::fs::rename(TmpPath, Path)) { |
| 204 | Path.push_back('\0'); |
| 205 | return makeStringError(EC, "cannot link %s to %s", ToLink.data(), |
| 206 | Path.data()); |
| 207 | } |
| 208 | // If `Path` was already a hard-link to the same underlying file then the |
| 209 | // temp file will be left so we need to remove it. Remove will not cause |
| 210 | // an error by default if the file is already gone so just blindly remove |
| 211 | // it rather than checking. |
| 212 | if (auto EC = sys::fs::remove(TmpPath)) { |
| 213 | TmpPath.push_back('\0'); |
| 214 | return makeStringError(EC, "could not remove %s", TmpPath.data()); |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 215 | } |
Jordan Rupprecht | fc832e9 | 2019-01-30 18:13:30 +0000 | [diff] [blame] | 216 | return Error::success(); |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 219 | static Error splitDWOToFile(const CopyConfig &Config, const Reader &Reader, |
| 220 | StringRef File, ElfType OutputElfType) { |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 221 | auto DWOFile = Reader.create(); |
Jordan Rupprecht | 971d4762 | 2019-02-01 15:20:36 +0000 | [diff] [blame] | 222 | auto OnlyKeepDWOPred = [&DWOFile](const SectionBase &Sec) { |
| 223 | return onlyKeepDWOPred(*DWOFile, Sec); |
| 224 | }; |
| 225 | if (Error E = DWOFile->removeSections(OnlyKeepDWOPred)) |
| 226 | return E; |
James Henderson | c040d5d | 2019-03-22 10:21:09 +0000 | [diff] [blame] | 227 | if (Config.OutputArch) { |
Jordan Rupprecht | 70038e0 | 2019-01-07 16:59:12 +0000 | [diff] [blame] | 228 | DWOFile->Machine = Config.OutputArch.getValue().EMachine; |
James Henderson | c040d5d | 2019-03-22 10:21:09 +0000 | [diff] [blame] | 229 | DWOFile->OSABI = Config.OutputArch.getValue().OSABI; |
| 230 | } |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 231 | FileBuffer FB(File); |
| 232 | auto Writer = createWriter(Config, *DWOFile, FB, OutputElfType); |
Jordan Rupprecht | 881cae7 | 2019-01-22 23:49:16 +0000 | [diff] [blame] | 233 | if (Error E = Writer->finalize()) |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 234 | return E; |
| 235 | return Writer->write(); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static Error dumpSectionToFile(StringRef SecName, StringRef Filename, |
| 239 | Object &Obj) { |
| 240 | for (auto &Sec : Obj.sections()) { |
| 241 | if (Sec.Name == SecName) { |
Jordan Rupprecht | 16a0de2 | 2018-12-20 00:57:06 +0000 | [diff] [blame] | 242 | if (Sec.OriginalData.empty()) |
Martin Storsjo | 8010c6be | 2019-01-22 10:57:59 +0000 | [diff] [blame] | 243 | return createStringError( |
| 244 | object_error::parse_failed, |
| 245 | "Can't dump section \"%s\": it has no contents", |
| 246 | SecName.str().c_str()); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 247 | Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr = |
| 248 | FileOutputBuffer::create(Filename, Sec.OriginalData.size()); |
| 249 | if (!BufferOrErr) |
| 250 | return BufferOrErr.takeError(); |
| 251 | std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr); |
| 252 | std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), |
| 253 | Buf->getBufferStart()); |
| 254 | if (Error E = Buf->commit()) |
| 255 | return E; |
| 256 | return Error::success(); |
| 257 | } |
| 258 | } |
Martin Storsjo | 8010c6be | 2019-01-22 10:57:59 +0000 | [diff] [blame] | 259 | return createStringError(object_error::parse_failed, "Section not found"); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 262 | static bool isCompressable(const SectionBase &Section) { |
George Rimar | ade3c70 | 2019-03-05 13:07:43 +0000 | [diff] [blame] | 263 | return !(Section.Flags & ELF::SHF_COMPRESSED) && |
| 264 | StringRef(Section.Name).startswith(".debug"); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static void replaceDebugSections( |
Fangrui Song | 3dfc3fb | 2019-03-15 10:27:28 +0000 | [diff] [blame] | 268 | Object &Obj, SectionPred &RemovePred, |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 269 | function_ref<bool(const SectionBase &)> shouldReplace, |
| 270 | function_ref<SectionBase *(const SectionBase *)> addSection) { |
George Rimar | d8a5c6c | 2019-03-11 11:01:24 +0000 | [diff] [blame] | 271 | // Build a list of the debug sections we are going to replace. |
| 272 | // We can't call `addSection` while iterating over sections, |
| 273 | // because it would mutate the sections array. |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 274 | SmallVector<SectionBase *, 13> ToReplace; |
George Rimar | d8a5c6c | 2019-03-11 11:01:24 +0000 | [diff] [blame] | 275 | for (auto &Sec : Obj.sections()) |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 276 | if (shouldReplace(Sec)) |
| 277 | ToReplace.push_back(&Sec); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 278 | |
George Rimar | d8a5c6c | 2019-03-11 11:01:24 +0000 | [diff] [blame] | 279 | // Build a mapping from original section to a new one. |
| 280 | DenseMap<SectionBase *, SectionBase *> FromTo; |
| 281 | for (SectionBase *S : ToReplace) |
| 282 | FromTo[S] = addSection(S); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 283 | |
George Rimar | d8a5c6c | 2019-03-11 11:01:24 +0000 | [diff] [blame] | 284 | // Now we want to update the target sections of relocation |
| 285 | // sections. Also we will update the relocations themselves |
| 286 | // to update the symbol references. |
| 287 | for (auto &Sec : Obj.sections()) |
| 288 | Sec.replaceSectionReferences(FromTo); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 289 | |
| 290 | RemovePred = [shouldReplace, RemovePred](const SectionBase &Sec) { |
| 291 | return shouldReplace(Sec) || RemovePred(Sec); |
| 292 | }; |
| 293 | } |
| 294 | |
Eugene Leviant | 2db1062 | 2019-02-13 07:34:54 +0000 | [diff] [blame] | 295 | static bool isUnneededSymbol(const Symbol &Sym) { |
| 296 | return !Sym.Referenced && |
| 297 | (Sym.Binding == STB_LOCAL || Sym.getShndx() == SHN_UNDEF) && |
| 298 | Sym.Type != STT_FILE && Sym.Type != STT_SECTION; |
| 299 | } |
| 300 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 301 | static Error updateAndRemoveSymbols(const CopyConfig &Config, Object &Obj) { |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 302 | // TODO: update or remove symbols only if there is an option that affects |
| 303 | // them. |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 304 | if (!Obj.SymbolTable) |
| 305 | return Error::success(); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 306 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 307 | Obj.SymbolTable->updateSymbols([&](Symbol &Sym) { |
| 308 | // Common and undefined symbols don't make sense as local symbols, and can |
| 309 | // even cause crashes if we localize those, so skip them. |
| 310 | if (!Sym.isCommon() && Sym.getShndx() != SHN_UNDEF && |
| 311 | ((Config.LocalizeHidden && |
| 312 | (Sym.Visibility == STV_HIDDEN || Sym.Visibility == STV_INTERNAL)) || |
| 313 | is_contained(Config.SymbolsToLocalize, Sym.Name))) |
| 314 | Sym.Binding = STB_LOCAL; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 315 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 316 | // Note: these two globalize flags have very similar names but different |
| 317 | // meanings: |
| 318 | // |
| 319 | // --globalize-symbol: promote a symbol to global |
| 320 | // --keep-global-symbol: all symbols except for these should be made local |
| 321 | // |
| 322 | // If --globalize-symbol is specified for a given symbol, it will be |
| 323 | // global in the output file even if it is not included via |
| 324 | // --keep-global-symbol. Because of that, make sure to check |
| 325 | // --globalize-symbol second. |
| 326 | if (!Config.SymbolsToKeepGlobal.empty() && |
| 327 | !is_contained(Config.SymbolsToKeepGlobal, Sym.Name) && |
| 328 | Sym.getShndx() != SHN_UNDEF) |
| 329 | Sym.Binding = STB_LOCAL; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 330 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 331 | if (is_contained(Config.SymbolsToGlobalize, Sym.Name) && |
| 332 | Sym.getShndx() != SHN_UNDEF) |
| 333 | Sym.Binding = STB_GLOBAL; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 334 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 335 | if (is_contained(Config.SymbolsToWeaken, Sym.Name) && |
| 336 | Sym.Binding == STB_GLOBAL) |
| 337 | Sym.Binding = STB_WEAK; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 338 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 339 | if (Config.Weaken && Sym.Binding == STB_GLOBAL && |
| 340 | Sym.getShndx() != SHN_UNDEF) |
| 341 | Sym.Binding = STB_WEAK; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 342 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 343 | const auto I = Config.SymbolsToRename.find(Sym.Name); |
| 344 | if (I != Config.SymbolsToRename.end()) |
| 345 | Sym.Name = I->getValue(); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 346 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 347 | if (!Config.SymbolsPrefix.empty() && Sym.Type != STT_SECTION) |
| 348 | Sym.Name = (Config.SymbolsPrefix + Sym.Name).str(); |
| 349 | }); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 350 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 351 | // The purpose of this loop is to mark symbols referenced by sections |
| 352 | // (like GroupSection or RelocationSection). This way, we know which |
| 353 | // symbols are still 'needed' and which are not. |
| 354 | if (Config.StripUnneeded || !Config.UnneededSymbolsToRemove.empty()) { |
| 355 | for (auto &Section : Obj.sections()) |
| 356 | Section.markSymbols(); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 357 | } |
| 358 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 359 | auto RemoveSymbolsPred = [&](const Symbol &Sym) { |
| 360 | if (is_contained(Config.SymbolsToKeep, Sym.Name) || |
| 361 | (Config.KeepFileSymbols && Sym.Type == STT_FILE)) |
| 362 | return false; |
| 363 | |
| 364 | if ((Config.DiscardMode == DiscardType::All || |
| 365 | (Config.DiscardMode == DiscardType::Locals && |
| 366 | StringRef(Sym.Name).startswith(".L"))) && |
| 367 | Sym.Binding == STB_LOCAL && Sym.getShndx() != SHN_UNDEF && |
| 368 | Sym.Type != STT_FILE && Sym.Type != STT_SECTION) |
| 369 | return true; |
| 370 | |
| 371 | if (Config.StripAll || Config.StripAllGNU) |
| 372 | return true; |
| 373 | |
| 374 | if (is_contained(Config.SymbolsToRemove, Sym.Name)) |
| 375 | return true; |
| 376 | |
| 377 | if ((Config.StripUnneeded || |
| 378 | is_contained(Config.UnneededSymbolsToRemove, Sym.Name)) && |
| 379 | isUnneededSymbol(Sym)) |
| 380 | return true; |
| 381 | |
| 382 | return false; |
| 383 | }; |
| 384 | |
| 385 | return Obj.removeSymbols(RemoveSymbolsPred); |
| 386 | } |
| 387 | |
| 388 | static Error replaceAndRemoveSections(const CopyConfig &Config, Object &Obj) { |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 389 | SectionPred RemovePred = [](const SectionBase &) { return false; }; |
| 390 | |
| 391 | // Removes: |
| 392 | if (!Config.ToRemove.empty()) { |
| 393 | RemovePred = [&Config](const SectionBase &Sec) { |
| 394 | return is_contained(Config.ToRemove, Sec.Name); |
| 395 | }; |
| 396 | } |
| 397 | |
| 398 | if (Config.StripDWO || !Config.SplitDWO.empty()) |
| 399 | RemovePred = [RemovePred](const SectionBase &Sec) { |
| 400 | return isDWOSection(Sec) || RemovePred(Sec); |
| 401 | }; |
| 402 | |
| 403 | if (Config.ExtractDWO) |
| 404 | RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { |
| 405 | return onlyKeepDWOPred(Obj, Sec) || RemovePred(Sec); |
| 406 | }; |
| 407 | |
| 408 | if (Config.StripAllGNU) |
| 409 | RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { |
| 410 | if (RemovePred(Sec)) |
| 411 | return true; |
| 412 | if ((Sec.Flags & SHF_ALLOC) != 0) |
| 413 | return false; |
| 414 | if (&Sec == Obj.SectionNames) |
| 415 | return false; |
| 416 | switch (Sec.Type) { |
| 417 | case SHT_SYMTAB: |
| 418 | case SHT_REL: |
| 419 | case SHT_RELA: |
| 420 | case SHT_STRTAB: |
| 421 | return true; |
| 422 | } |
| 423 | return isDebugSection(Sec); |
| 424 | }; |
| 425 | |
| 426 | if (Config.StripSections) { |
| 427 | RemovePred = [RemovePred](const SectionBase &Sec) { |
James Henderson | b5de5e2 | 2019-03-14 11:47:41 +0000 | [diff] [blame] | 428 | return RemovePred(Sec) || Sec.ParentSegment == nullptr; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 429 | }; |
| 430 | } |
| 431 | |
| 432 | if (Config.StripDebug) { |
| 433 | RemovePred = [RemovePred](const SectionBase &Sec) { |
| 434 | return RemovePred(Sec) || isDebugSection(Sec); |
| 435 | }; |
| 436 | } |
| 437 | |
| 438 | if (Config.StripNonAlloc) |
| 439 | RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { |
| 440 | if (RemovePred(Sec)) |
| 441 | return true; |
| 442 | if (&Sec == Obj.SectionNames) |
| 443 | return false; |
James Henderson | b5de5e2 | 2019-03-14 11:47:41 +0000 | [diff] [blame] | 444 | return (Sec.Flags & SHF_ALLOC) == 0 && Sec.ParentSegment == nullptr; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | if (Config.StripAll) |
| 448 | RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { |
| 449 | if (RemovePred(Sec)) |
| 450 | return true; |
| 451 | if (&Sec == Obj.SectionNames) |
| 452 | return false; |
| 453 | if (StringRef(Sec.Name).startswith(".gnu.warning")) |
| 454 | return false; |
James Henderson | b5de5e2 | 2019-03-14 11:47:41 +0000 | [diff] [blame] | 455 | if (Sec.ParentSegment != nullptr) |
| 456 | return false; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 457 | return (Sec.Flags & SHF_ALLOC) == 0; |
| 458 | }; |
| 459 | |
| 460 | // Explicit copies: |
Jake Ehrlich | 85985ed | 2018-12-06 02:03:53 +0000 | [diff] [blame] | 461 | if (!Config.OnlySection.empty()) { |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 462 | RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) { |
| 463 | // Explicitly keep these sections regardless of previous removes. |
Jake Ehrlich | 85985ed | 2018-12-06 02:03:53 +0000 | [diff] [blame] | 464 | if (is_contained(Config.OnlySection, Sec.Name)) |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 465 | return false; |
| 466 | |
| 467 | // Allow all implicit removes. |
| 468 | if (RemovePred(Sec)) |
| 469 | return true; |
| 470 | |
| 471 | // Keep special sections. |
| 472 | if (Obj.SectionNames == &Sec) |
| 473 | return false; |
| 474 | if (Obj.SymbolTable == &Sec || |
| 475 | (Obj.SymbolTable && Obj.SymbolTable->getStrTab() == &Sec)) |
| 476 | return false; |
| 477 | |
| 478 | // Remove everything else. |
| 479 | return true; |
| 480 | }; |
| 481 | } |
| 482 | |
Jordan Rupprecht | c5bae78 | 2018-11-13 19:32:27 +0000 | [diff] [blame] | 483 | if (!Config.KeepSection.empty()) { |
Fangrui Song | e9f34b0 | 2018-11-12 23:46:22 +0000 | [diff] [blame] | 484 | RemovePred = [&Config, RemovePred](const SectionBase &Sec) { |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 485 | // Explicitly keep these sections regardless of previous removes. |
Jordan Rupprecht | c5bae78 | 2018-11-13 19:32:27 +0000 | [diff] [blame] | 486 | if (is_contained(Config.KeepSection, Sec.Name)) |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 487 | return false; |
| 488 | // Otherwise defer to RemovePred. |
| 489 | return RemovePred(Sec); |
| 490 | }; |
| 491 | } |
| 492 | |
| 493 | // This has to be the last predicate assignment. |
| 494 | // If the option --keep-symbol has been specified |
| 495 | // and at least one of those symbols is present |
| 496 | // (equivalently, the updated symbol table is not empty) |
| 497 | // the symbol table and the string table should not be removed. |
| 498 | if ((!Config.SymbolsToKeep.empty() || Config.KeepFileSymbols) && |
| 499 | Obj.SymbolTable && !Obj.SymbolTable->empty()) { |
| 500 | RemovePred = [&Obj, RemovePred](const SectionBase &Sec) { |
| 501 | if (&Sec == Obj.SymbolTable || &Sec == Obj.SymbolTable->getStrTab()) |
| 502 | return false; |
| 503 | return RemovePred(Sec); |
| 504 | }; |
| 505 | } |
| 506 | |
| 507 | if (Config.CompressionType != DebugCompressionType::None) |
Fangrui Song | 3dfc3fb | 2019-03-15 10:27:28 +0000 | [diff] [blame] | 508 | replaceDebugSections(Obj, RemovePred, isCompressable, |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 509 | [&Config, &Obj](const SectionBase *S) { |
| 510 | return &Obj.addSection<CompressedSection>( |
| 511 | *S, Config.CompressionType); |
| 512 | }); |
| 513 | else if (Config.DecompressDebugSections) |
| 514 | replaceDebugSections( |
Fangrui Song | 3dfc3fb | 2019-03-15 10:27:28 +0000 | [diff] [blame] | 515 | Obj, RemovePred, |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 516 | [](const SectionBase &S) { return isa<CompressedSection>(&S); }, |
| 517 | [&Obj](const SectionBase *S) { |
| 518 | auto CS = cast<CompressedSection>(S); |
| 519 | return &Obj.addSection<DecompressedSection>(*CS); |
| 520 | }); |
| 521 | |
George Rimar | e6963be | 2019-03-25 12:34:25 +0000 | [diff] [blame^] | 522 | return Obj.removeSections(RemovePred); |
| 523 | } |
| 524 | |
| 525 | // This function handles the high level operations of GNU objcopy including |
| 526 | // handling command line options. It's important to outline certain properties |
| 527 | // we expect to hold of the command line operations. Any operation that "keeps" |
| 528 | // should keep regardless of a remove. Additionally any removal should respect |
| 529 | // any previous removals. Lastly whether or not something is removed shouldn't |
| 530 | // depend a) on the order the options occur in or b) on some opaque priority |
| 531 | // system. The only priority is that keeps/copies overrule removes. |
| 532 | static Error handleArgs(const CopyConfig &Config, Object &Obj, |
| 533 | const Reader &Reader, ElfType OutputElfType) { |
| 534 | |
| 535 | if (!Config.SplitDWO.empty()) |
| 536 | if (Error E = |
| 537 | splitDWOToFile(Config, Reader, Config.SplitDWO, OutputElfType)) |
| 538 | return E; |
| 539 | |
| 540 | if (Config.OutputArch) { |
| 541 | Obj.Machine = Config.OutputArch.getValue().EMachine; |
| 542 | Obj.OSABI = Config.OutputArch.getValue().OSABI; |
| 543 | } |
| 544 | |
| 545 | if (Error E = updateAndRemoveSymbols(Config, Obj)) |
| 546 | return E; |
| 547 | |
| 548 | if (Error E = replaceAndRemoveSections(Config, Obj)) |
Jordan Rupprecht | 971d4762 | 2019-02-01 15:20:36 +0000 | [diff] [blame] | 549 | return E; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 550 | |
| 551 | if (!Config.SectionsToRename.empty()) { |
| 552 | for (auto &Sec : Obj.sections()) { |
| 553 | const auto Iter = Config.SectionsToRename.find(Sec.Name); |
| 554 | if (Iter != Config.SectionsToRename.end()) { |
| 555 | const SectionRename &SR = Iter->second; |
| 556 | Sec.Name = SR.NewName; |
Jordan Rupprecht | c892741 | 2019-01-29 15:05:38 +0000 | [diff] [blame] | 557 | if (SR.NewFlags.hasValue()) |
| 558 | Sec.Flags = |
| 559 | setSectionFlagsPreserveMask(Sec.Flags, SR.NewFlags.getValue()); |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if (!Config.SetSectionFlags.empty()) { |
| 565 | for (auto &Sec : Obj.sections()) { |
| 566 | const auto Iter = Config.SetSectionFlags.find(Sec.Name); |
| 567 | if (Iter != Config.SetSectionFlags.end()) { |
| 568 | const SectionFlagsUpdate &SFU = Iter->second; |
| 569 | Sec.Flags = setSectionFlagsPreserveMask(Sec.Flags, SFU.NewFlags); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | } |
Eugene Leviant | c76671b | 2019-03-12 12:41:06 +0000 | [diff] [blame] | 573 | |
| 574 | for (const auto &Flag : Config.AddSection) { |
| 575 | std::pair<StringRef, StringRef> SecPair = Flag.split("="); |
| 576 | StringRef SecName = SecPair.first; |
| 577 | StringRef File = SecPair.second; |
| 578 | ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr = |
| 579 | MemoryBuffer::getFile(File); |
| 580 | if (!BufOrErr) |
| 581 | return createFileError(File, errorCodeToError(BufOrErr.getError())); |
| 582 | std::unique_ptr<MemoryBuffer> Buf = std::move(*BufOrErr); |
| 583 | ArrayRef<uint8_t> Data( |
| 584 | reinterpret_cast<const uint8_t *>(Buf->getBufferStart()), |
| 585 | Buf->getBufferSize()); |
| 586 | OwnedDataSection &NewSection = |
| 587 | Obj.addSection<OwnedDataSection>(SecName, Data); |
| 588 | if (SecName.startswith(".note") && SecName != ".note.GNU-stack") |
| 589 | NewSection.Type = SHT_NOTE; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Eugene Leviant | c76671b | 2019-03-12 12:41:06 +0000 | [diff] [blame] | 592 | for (const auto &Flag : Config.DumpSection) { |
| 593 | std::pair<StringRef, StringRef> SecPair = Flag.split("="); |
| 594 | StringRef SecName = SecPair.first; |
| 595 | StringRef File = SecPair.second; |
| 596 | if (Error E = dumpSectionToFile(SecName, File, Obj)) |
| 597 | return createFileError(Config.InputFilename, std::move(E)); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | if (!Config.AddGnuDebugLink.empty()) |
| 601 | Obj.addSection<GnuDebugLinkSection>(Config.AddGnuDebugLink); |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 602 | |
Eugene Leviant | 51c1f64 | 2019-02-25 14:12:41 +0000 | [diff] [blame] | 603 | for (const NewSymbolInfo &SI : Config.SymbolsToAdd) { |
| 604 | SectionBase *Sec = Obj.findSection(SI.SectionName); |
| 605 | uint64_t Value = Sec ? Sec->Addr + SI.Value : SI.Value; |
Simon Pilgrim | 65706cf | 2019-02-27 10:19:53 +0000 | [diff] [blame] | 606 | Obj.SymbolTable->addSymbol( |
| 607 | SI.SymbolName, SI.Bind, SI.Type, Sec, Value, SI.Visibility, |
| 608 | Sec ? (uint16_t)SYMBOL_SIMPLE_INDEX : (uint16_t)SHN_ABS, 0); |
Eugene Leviant | 51c1f64 | 2019-02-25 14:12:41 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Eugene Leviant | 53350d0 | 2019-02-26 09:24:22 +0000 | [diff] [blame] | 611 | if (Config.EntryExpr) |
| 612 | Obj.Entry = Config.EntryExpr(Obj.Entry); |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 613 | return Error::success(); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 616 | Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In, |
| 617 | Buffer &Out) { |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 618 | BinaryReader Reader(Config.BinaryArch, &In); |
| 619 | std::unique_ptr<Object> Obj = Reader.create(); |
| 620 | |
Jordan Rupprecht | 70038e0 | 2019-01-07 16:59:12 +0000 | [diff] [blame] | 621 | // Prefer OutputArch (-O<format>) if set, otherwise fallback to BinaryArch |
| 622 | // (-B<arch>). |
| 623 | const ElfType OutputElfType = getOutputElfType( |
| 624 | Config.OutputArch ? Config.OutputArch.getValue() : Config.BinaryArch); |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 625 | if (Error E = handleArgs(Config, *Obj, Reader, OutputElfType)) |
| 626 | return E; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 627 | std::unique_ptr<Writer> Writer = |
| 628 | createWriter(Config, *Obj, Out, OutputElfType); |
Jordan Rupprecht | 881cae7 | 2019-01-22 23:49:16 +0000 | [diff] [blame] | 629 | if (Error E = Writer->finalize()) |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 630 | return E; |
| 631 | return Writer->write(); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 634 | Error executeObjcopyOnBinary(const CopyConfig &Config, |
| 635 | object::ELFObjectFileBase &In, Buffer &Out) { |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 636 | ELFReader Reader(&In); |
| 637 | std::unique_ptr<Object> Obj = Reader.create(); |
Jordan Rupprecht | 70038e0 | 2019-01-07 16:59:12 +0000 | [diff] [blame] | 638 | // Prefer OutputArch (-O<format>) if set, otherwise infer it from the input. |
| 639 | const ElfType OutputElfType = |
| 640 | Config.OutputArch ? getOutputElfType(Config.OutputArch.getValue()) |
| 641 | : getOutputElfType(In); |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 642 | ArrayRef<uint8_t> BuildIdBytes; |
| 643 | |
| 644 | if (!Config.BuildIdLinkDir.empty()) { |
| 645 | BuildIdBytes = unwrapOrError(findBuildID(In)); |
| 646 | if (BuildIdBytes.size() < 2) |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 647 | return createFileError( |
| 648 | Config.InputFilename, |
| 649 | createStringError(object_error::parse_failed, |
| 650 | "build ID is smaller than two bytes.")); |
Jake Ehrlich | 8ad7779 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Jordan Rupprecht | fc832e9 | 2019-01-30 18:13:30 +0000 | [diff] [blame] | 653 | if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkInput) |
| 654 | if (Error E = |
| 655 | linkToBuildIdDir(Config, Config.InputFilename, |
| 656 | Config.BuildIdLinkInput.getValue(), BuildIdBytes)) |
| 657 | return E; |
| 658 | |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 659 | if (Error E = handleArgs(Config, *Obj, Reader, OutputElfType)) |
| 660 | return E; |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 661 | std::unique_ptr<Writer> Writer = |
| 662 | createWriter(Config, *Obj, Out, OutputElfType); |
Jordan Rupprecht | 881cae7 | 2019-01-22 23:49:16 +0000 | [diff] [blame] | 663 | if (Error E = Writer->finalize()) |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 664 | return E; |
Jordan Rupprecht | 881cae7 | 2019-01-22 23:49:16 +0000 | [diff] [blame] | 665 | if (Error E = Writer->write()) |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 666 | return E; |
Jordan Rupprecht | fc832e9 | 2019-01-30 18:13:30 +0000 | [diff] [blame] | 667 | if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkOutput) |
| 668 | if (Error E = |
| 669 | linkToBuildIdDir(Config, Config.OutputFilename, |
| 670 | Config.BuildIdLinkOutput.getValue(), BuildIdBytes)) |
| 671 | return E; |
| 672 | |
Jordan Rupprecht | 307deab | 2019-01-30 14:36:53 +0000 | [diff] [blame] | 673 | return Error::success(); |
Alexander Shaposhnikov | f4e75a5 | 2018-10-29 21:22:58 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | } // end namespace elf |
| 677 | } // end namespace objcopy |
| 678 | } // end namespace llvm |