Skip to content

Commit 3681b34

Browse files
committed
Add err-msg & ref to doc
1 parent 6ef0941 commit 3681b34

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,23 @@ static Error addSection(const NewSectionInfo &NewSection, Object &Obj) {
360360
static Expected<Section &> findSection(StringRef SecName, Object &O) {
361361
StringRef SegName;
362362
std::tie(SegName, SecName) = SecName.split(",");
363+
// For compactness, intermediate object files (MH_OBJECT) contain
364+
// only one segment in which all sections are placed.
365+
// The static linker places each section in the named segment when building
366+
// the final product (any file that is not of type MH_OBJECT).
367+
//
368+
// Source:
369+
// https://math-atlas.sourceforge.net/devel/assembly/MachORuntime.pdf
370+
// page 57
363371
if (O.Header.FileType == MachO::HeaderFileType::MH_OBJECT) {
364372
for (const auto& LC : O.LoadCommands)
365373
for (const auto& Sec : LC.Sections)
366374
if (Sec->Segname == SegName && Sec->Sectname == SecName)
367375
return *Sec;
376+
377+
StringRef ErrMsg = "could not find section with name '%s' in '%s' segment";
378+
return createStringError(errc::invalid_argument, ErrMsg.str().c_str(),
379+
SecName.str().c_str(), SegName.str().c_str());
368380
}
369381
auto FoundSeg =
370382
llvm::find_if(O.LoadCommands, [SegName](const LoadCommand &LC) {

0 commit comments

Comments
 (0)