Skip to content

Commit c465429

Browse files
committed
[llvm-objcopy] Delete --build-id-link-{dir,input,output}
The few options are niche. They solved a problem which was traditionally solved with more shell commands (`llvm-readelf -n` fetches the Build ID. Then `ln` is used to hard link the file to a directory derived from the Build ID.) Due to limitation, they are no longer used by Fuchsia and they don't appear to be used elsewhere (checked with Google Search and Debian Code Search). So delete them without a transition period. Announcement: https://lists.llvm.org/pipermail/llvm-dev/2021-February/148446.html Differential Revision: https://reviews.llvm.org/D96310
1 parent 1dd66e6 commit c465429

File tree

13 files changed

+21
-287
lines changed

13 files changed

+21
-287
lines changed

llvm/docs/CommandGuide/llvm-objcopy.rst

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,6 @@ them.
285285
Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
286286
section references. Any invalid sh_link fields will be set to zero.
287287

288-
.. option:: --build-id-link-dir <dir>
289-
290-
Set the directory used by :option:`--build-id-link-input` and
291-
:option:`--build-id-link-output`.
292-
293-
.. option:: --build-id-link-input <suffix>
294-
295-
Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
296-
specified by :option:`--build-id-link-dir`. The path used is derived from the
297-
hex build ID.
298-
299-
.. option:: --build-id-link-output <suffix>
300-
301-
Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
302-
specified by :option:`--build-id-link-dir`. The path used is derived from the
303-
hex build ID.
304-
305288
.. option:: --change-start <incr>, --adjust-start
306289

307290
Add ``<incr>`` to the program's start address. Can be specified multiple

llvm/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ During this release ...
124124
Changes to the LLVM tools
125125
---------------------------------
126126

127+
* The options ``--build-id-link-{dir,input,output}`` have been deleted.
128+
(`D96310 <https://reviews.llvm.org/D96310>`_)
129+
127130
Changes to LLDB
128131
---------------------------------
129132

llvm/test/tools/llvm-objcopy/ELF/bad-build-id.test

Lines changed: 0 additions & 21 deletions
This file was deleted.

llvm/test/tools/llvm-objcopy/ELF/build-id-link-dir.test

Lines changed: 0 additions & 56 deletions
This file was deleted.

llvm/test/tools/llvm-objcopy/ELF/no-build-id-no-notes.test

Lines changed: 0 additions & 11 deletions
This file was deleted.

llvm/test/tools/llvm-objcopy/ELF/no-build-id.test

Lines changed: 0 additions & 21 deletions
This file was deleted.

llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,15 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) {
249249
if (Error E = addGnuDebugLink(Obj, Config.AddGnuDebugLink))
250250
return E;
251251

252-
if (Config.AllowBrokenLinks || !Config.BuildIdLinkDir.empty() ||
253-
Config.BuildIdLinkInput || Config.BuildIdLinkOutput ||
254-
!Config.SplitDWO.empty() || !Config.SymbolsPrefix.empty() ||
255-
!Config.AllocSectionsPrefix.empty() || !Config.DumpSection.empty() ||
256-
!Config.KeepSection.empty() || Config.NewSymbolVisibility ||
257-
!Config.SymbolsToGlobalize.empty() || !Config.SymbolsToKeep.empty() ||
258-
!Config.SymbolsToLocalize.empty() || !Config.SymbolsToWeaken.empty() ||
259-
!Config.SymbolsToKeepGlobal.empty() || !Config.SectionsToRename.empty() ||
260-
!Config.SetSectionAlignment.empty() || Config.ExtractDWO ||
261-
Config.LocalizeHidden || Config.PreserveDates || Config.StripDWO ||
262-
Config.StripNonAlloc || Config.StripSections ||
252+
if (Config.AllowBrokenLinks || !Config.SplitDWO.empty() ||
253+
!Config.SymbolsPrefix.empty() || !Config.AllocSectionsPrefix.empty() ||
254+
!Config.DumpSection.empty() || !Config.KeepSection.empty() ||
255+
Config.NewSymbolVisibility || !Config.SymbolsToGlobalize.empty() ||
256+
!Config.SymbolsToKeep.empty() || !Config.SymbolsToLocalize.empty() ||
257+
!Config.SymbolsToWeaken.empty() || !Config.SymbolsToKeepGlobal.empty() ||
258+
!Config.SectionsToRename.empty() || !Config.SetSectionAlignment.empty() ||
259+
Config.ExtractDWO || Config.LocalizeHidden || Config.PreserveDates ||
260+
Config.StripDWO || Config.StripNonAlloc || Config.StripSections ||
263261
Config.StripSwiftSymbols || Config.Weaken ||
264262
Config.DecompressDebugSections ||
265263
Config.DiscardMode == DiscardType::Locals ||

llvm/tools/llvm-objcopy/CopyConfig.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,6 @@ parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
607607
Config.GnuDebugLinkCRC32 =
608608
llvm::crc32(arrayRefFromStringRef(Debug->getBuffer()));
609609
}
610-
Config.BuildIdLinkDir = InputArgs.getLastArgValue(OBJCOPY_build_id_link_dir);
611-
if (InputArgs.hasArg(OBJCOPY_build_id_link_input))
612-
Config.BuildIdLinkInput =
613-
InputArgs.getLastArgValue(OBJCOPY_build_id_link_input);
614-
if (InputArgs.hasArg(OBJCOPY_build_id_link_output))
615-
Config.BuildIdLinkOutput =
616-
InputArgs.getLastArgValue(OBJCOPY_build_id_link_output);
617610
Config.SplitDWO = InputArgs.getLastArgValue(OBJCOPY_split_dwo);
618611
Config.SymbolsPrefix = InputArgs.getLastArgValue(OBJCOPY_prefix_symbols);
619612
Config.AllocSectionsPrefix =

llvm/tools/llvm-objcopy/CopyConfig.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ struct CopyConfig {
163163
StringRef AddGnuDebugLink;
164164
// Cached gnu_debuglink's target CRC
165165
uint32_t GnuDebugLinkCRC32;
166-
StringRef BuildIdLinkDir;
167-
Optional<StringRef> BuildIdLinkInput;
168-
Optional<StringRef> BuildIdLinkOutput;
169166
Optional<StringRef> ExtractPartition;
170167
StringRef SplitDWO;
171168
StringRef SymbolsPrefix;

llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -166,103 +166,13 @@ static std::unique_ptr<Writer> createWriter(const CopyConfig &Config,
166166
}
167167
}
168168

169-
template <class ELFT>
170-
static Expected<ArrayRef<uint8_t>>
171-
findBuildID(const CopyConfig &Config, const object::ELFFile<ELFT> &In) {
172-
auto PhdrsOrErr = In.program_headers();
173-
if (auto Err = PhdrsOrErr.takeError())
174-
return createFileError(Config.InputFilename, std::move(Err));
175-
176-
for (const auto &Phdr : *PhdrsOrErr) {
177-
if (Phdr.p_type != PT_NOTE)
178-
continue;
179-
Error Err = Error::success();
180-
for (auto Note : In.notes(Phdr, Err))
181-
if (Note.getType() == NT_GNU_BUILD_ID && Note.getName() == ELF_NOTE_GNU)
182-
return Note.getDesc();
183-
if (Err)
184-
return createFileError(Config.InputFilename, std::move(Err));
185-
}
186-
187-
return createFileError(Config.InputFilename,
188-
createStringError(llvm::errc::invalid_argument,
189-
"could not find build ID"));
190-
}
191-
192-
static Expected<ArrayRef<uint8_t>>
193-
findBuildID(const CopyConfig &Config, const object::ELFObjectFileBase &In) {
194-
if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(&In))
195-
return findBuildID(Config, O->getELFFile());
196-
else if (auto *O = dyn_cast<ELFObjectFile<ELF64LE>>(&In))
197-
return findBuildID(Config, O->getELFFile());
198-
else if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(&In))
199-
return findBuildID(Config, O->getELFFile());
200-
else if (auto *O = dyn_cast<ELFObjectFile<ELF64BE>>(&In))
201-
return findBuildID(Config, O->getELFFile());
202-
203-
llvm_unreachable("Bad file format");
204-
}
205-
206169
template <class... Ts>
207170
static Error makeStringError(std::error_code EC, const Twine &Msg,
208171
Ts &&... Args) {
209172
std::string FullMsg = (EC.message() + ": " + Msg).str();
210173
return createStringError(EC, FullMsg.c_str(), std::forward<Ts>(Args)...);
211174
}
212175

213-
#define MODEL_8 "%%%%%%%%"
214-
#define MODEL_16 MODEL_8 MODEL_8
215-
#define MODEL_32 (MODEL_16 MODEL_16)
216-
217-
static Error linkToBuildIdDir(const CopyConfig &Config, StringRef ToLink,
218-
StringRef Suffix,
219-
ArrayRef<uint8_t> BuildIdBytes) {
220-
SmallString<128> Path = Config.BuildIdLinkDir;
221-
sys::path::append(Path, llvm::toHex(BuildIdBytes[0], /*LowerCase*/ true));
222-
if (auto EC = sys::fs::create_directories(Path))
223-
return createFileError(
224-
Path.str(),
225-
makeStringError(EC, "cannot create build ID link directory"));
226-
227-
sys::path::append(Path,
228-
llvm::toHex(BuildIdBytes.slice(1), /*LowerCase*/ true));
229-
Path += Suffix;
230-
SmallString<128> TmpPath;
231-
// create_hard_link races so we need to link to a temporary path but
232-
// we want to make sure that we choose a filename that does not exist.
233-
// By using 32 model characters we get 128-bits of entropy. It is
234-
// unlikely that this string has ever existed before much less exists
235-
// on this disk or in the current working directory.
236-
// Additionally we prepend the original Path for debugging but also
237-
// because it ensures that we're linking within a directory on the same
238-
// partition on the same device which is critical. It has the added
239-
// win of yet further decreasing the odds of a conflict.
240-
sys::fs::createUniquePath(Twine(Path) + "-" + MODEL_32 + ".tmp", TmpPath,
241-
/*MakeAbsolute*/ false);
242-
if (auto EC = sys::fs::create_hard_link(ToLink, TmpPath)) {
243-
Path.push_back('\0');
244-
return makeStringError(EC, "cannot link '%s' to '%s'", ToLink.data(),
245-
Path.data());
246-
}
247-
// We then atomically rename the link into place which will just move the
248-
// link. If rename fails something is more seriously wrong so just return
249-
// an error.
250-
if (auto EC = sys::fs::rename(TmpPath, Path)) {
251-
Path.push_back('\0');
252-
return makeStringError(EC, "cannot link '%s' to '%s'", ToLink.data(),
253-
Path.data());
254-
}
255-
// If `Path` was already a hard-link to the same underlying file then the
256-
// temp file will be left so we need to remove it. Remove will not cause
257-
// an error by default if the file is already gone so just blindly remove
258-
// it rather than checking.
259-
if (auto EC = sys::fs::remove(TmpPath)) {
260-
TmpPath.push_back('\0');
261-
return makeStringError(EC, "could not remove '%s'", TmpPath.data());
262-
}
263-
return Error::success();
264-
}
265-
266176
static Error splitDWOToFile(const CopyConfig &Config, const Reader &Reader,
267177
StringRef File, ElfType OutputElfType) {
268178
Expected<std::unique_ptr<Object>> DWOFile = Reader.create(false);
@@ -828,37 +738,12 @@ Error executeObjcopyOnBinary(const CopyConfig &Config,
828738
const ElfType OutputElfType =
829739
Config.OutputArch ? getOutputElfType(Config.OutputArch.getValue())
830740
: getOutputElfType(In);
831-
ArrayRef<uint8_t> BuildIdBytes;
832-
833-
if (!Config.BuildIdLinkDir.empty()) {
834-
auto BuildIdBytesOrErr = findBuildID(Config, In);
835-
if (auto E = BuildIdBytesOrErr.takeError())
836-
return E;
837-
BuildIdBytes = *BuildIdBytesOrErr;
838-
839-
if (BuildIdBytes.size() < 2)
840-
return createFileError(
841-
Config.InputFilename,
842-
createStringError(object_error::parse_failed,
843-
"build ID is smaller than two bytes"));
844-
}
845-
846-
if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkInput)
847-
if (Error E =
848-
linkToBuildIdDir(Config, Config.InputFilename,
849-
Config.BuildIdLinkInput.getValue(), BuildIdBytes))
850-
return E;
851741

852742
if (Error E = handleArgs(Config, **Obj, Reader, OutputElfType))
853743
return createFileError(Config.InputFilename, std::move(E));
854744

855745
if (Error E = writeOutput(Config, **Obj, Out, OutputElfType))
856746
return createFileError(Config.InputFilename, std::move(E));
857-
if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkOutput)
858-
if (Error E =
859-
linkToBuildIdDir(Config, Config.OutputFilename,
860-
Config.BuildIdLinkOutput.getValue(), BuildIdBytes))
861-
return createFileError(Config.OutputFilename, std::move(E));
862747

863748
return Error::success();
864749
}

llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,12 @@ static Error isValidMachOCannonicalName(StringRef Name) {
327327
}
328328

329329
static Error handleArgs(const CopyConfig &Config, Object &Obj) {
330-
if (Config.AllowBrokenLinks || !Config.BuildIdLinkDir.empty() ||
331-
Config.BuildIdLinkInput || Config.BuildIdLinkOutput ||
332-
!Config.SplitDWO.empty() || !Config.SymbolsPrefix.empty() ||
333-
!Config.AllocSectionsPrefix.empty() || !Config.KeepSection.empty() ||
334-
Config.NewSymbolVisibility || !Config.SymbolsToGlobalize.empty() ||
335-
!Config.SymbolsToKeep.empty() || !Config.SymbolsToLocalize.empty() ||
336-
!Config.SymbolsToWeaken.empty() || !Config.SymbolsToKeepGlobal.empty() ||
337-
!Config.SectionsToRename.empty() ||
330+
if (Config.AllowBrokenLinks || !Config.SplitDWO.empty() ||
331+
!Config.SymbolsPrefix.empty() || !Config.AllocSectionsPrefix.empty() ||
332+
!Config.KeepSection.empty() || Config.NewSymbolVisibility ||
333+
!Config.SymbolsToGlobalize.empty() || !Config.SymbolsToKeep.empty() ||
334+
!Config.SymbolsToLocalize.empty() || !Config.SymbolsToWeaken.empty() ||
335+
!Config.SymbolsToKeepGlobal.empty() || !Config.SectionsToRename.empty() ||
338336
!Config.UnneededSymbolsToRemove.empty() ||
339337
!Config.SetSectionAlignment.empty() || !Config.SetSectionFlags.empty() ||
340338
Config.ExtractDWO || Config.LocalizeHidden || Config.PreserveDates ||

llvm/tools/llvm-objcopy/ObjcopyOpts.td

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,6 @@ defm prefix_alloc_sections
196196
: Eq<"prefix-alloc-sections", "Add <prefix> to the start of every allocated section name">,
197197
MetaVarName<"prefix">;
198198

199-
defm build_id_link_dir
200-
: Eq<"build-id-link-dir", "Set directory for --build-id-link-input and "
201-
"--build-id-link-output to <dir>">,
202-
MetaVarName<"dir">;
203-
defm build_id_link_input
204-
: Eq<"build-id-link-input", "Hard-link the input to <dir>/xx/xxx<suffix> "
205-
"name derived from hex build ID">,
206-
MetaVarName<"suffix">;
207-
defm build_id_link_output
208-
: Eq<"build-id-link-output", "Hard-link the output to <dir>/xx/xxx<suffix> "
209-
"name derived from hex build ID">,
210-
MetaVarName<"suffix">;
211-
212199
defm set_start : Eq<"set-start", "Set the start address to <addr>. Overrides "
213200
"any previous --change-start or --adjust-start values.">,
214201
MetaVarName<"addr">;

llvm/tools/llvm-objcopy/wasm/WasmObjcopy.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) {
7272
Obj.addSectionWithOwnedContents(Sec, std::move(Buf));
7373
}
7474

75-
if (!Config.AddGnuDebugLink.empty() || !Config.BuildIdLinkDir.empty() ||
76-
Config.BuildIdLinkInput || Config.BuildIdLinkOutput ||
77-
Config.ExtractPartition || !Config.SplitDWO.empty() ||
78-
!Config.SymbolsPrefix.empty() || !Config.AllocSectionsPrefix.empty() ||
75+
if (!Config.AddGnuDebugLink.empty() || Config.ExtractPartition ||
76+
!Config.SplitDWO.empty() || !Config.SymbolsPrefix.empty() ||
77+
!Config.AllocSectionsPrefix.empty() ||
7978
Config.DiscardMode != DiscardType::None || Config.NewSymbolVisibility ||
8079
!Config.SymbolsToAdd.empty() || !Config.RPathToAdd.empty() ||
8180
!Config.OnlySection.empty() || !Config.SymbolsToGlobalize.empty() ||

0 commit comments

Comments
 (0)