Skip to content

Commit 76ccb57

Browse files
committed
Made Changes
1 parent 02fb5c0 commit 76ccb57

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

llvm/docs/CommandGuide/llvm-objcopy.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ multiple file formats.
178178
specified ``<flag>`` values. Can be specified multiple times to update multiple
179179
sections.
180180

181+
.. option:: --verbose
182+
183+
List all object files modified.
184+
181185
Supported flag names are `alloc`, `load`, `noload`, `readonly`, `exclude`,
182186
`debug`, `code`, `data`, `rom`, `share`, `contents`, `merge`, `strings`, and
183187
`large`. Not all flags are meaningful for all object file formats or target

llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static Error replaceAndRemoveSections(const CommonConfig &Config,
546546
};
547547
}
548548

549-
if (Error E = Obj.removeSections(ELFConfig.AllowBrokenLinks, RemovePred))
549+
if (Error E = Obj.removeSections(ELFConfig.AllowBrokenLinks, RemovePred, Config.Verbose))
550550
return E;
551551

552552
if (Error E = Obj.compressOrDecompressSections(Config))
@@ -782,7 +782,7 @@ static Error verifyNoteSection(StringRef Name, endianness Endianness,
782782
// system. The only priority is that keeps/copies overrule removes.
783783
static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
784784
ElfType OutputElfType, Object &Obj) {
785-
Obj.isVerboseEnabled = Config.Verbose;
785+
Obj.VerboseOutput = Config.Verbose;
786786
if (Config.OutputArch) {
787787
Obj.Machine = Config.OutputArch->EMachine;
788788
Obj.OSABI = Config.OutputArch->OSABI;
@@ -791,7 +791,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
791791
if (!Config.SplitDWO.empty() && Config.ExtractDWO) {
792792
return Obj.removeSections(
793793
ELFConfig.AllowBrokenLinks,
794-
[&Obj](const SectionBase &Sec) { return onlyKeepDWOPred(Obj, Sec); });
794+
[&Obj](const SectionBase &Sec) { return onlyKeepDWOPred(Obj, Sec); }, Config.Verbose);
795795
}
796796

797797
// Dump sections before add/remove for compatibility with GNU objcopy.

llvm/lib/ObjCopy/ELF/ELFObject.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,11 @@ Error SymbolTableSection::removeSymbols(
766766
function_ref<bool(const Symbol &)> ToRemove) {
767767
Symbols.erase(
768768
std::remove_if(std::begin(Symbols) + 1, std::end(Symbols),
769-
[ToRemove](const SymPtr &Sym) {
769+
[&](const SymPtr &Sym) {
770770
if (ToRemove(*Sym)) {
771-
llvm::outs() << "Symbols Removed:" << Sym->Name<< "\n";
772-
return true;
771+
if(VerboseOutput)
772+
outs() << "Symbols Removed:" << Sym->Name<< "\n";
773+
return true;
773774
}
774775
return false;
775776
}));
@@ -779,7 +780,6 @@ Error SymbolTableSection::removeSymbols(
779780
if (Size < PrevSize)
780781
IndicesChanged = true;
781782
assignIndices();
782-
return Error::success();
783783
}
784784

785785
void SymbolTableSection::replaceSectionReferences(
@@ -2201,7 +2201,7 @@ Error Object::updateSectionData(SectionBase &S, ArrayRef<uint8_t> Data) {
22012201
}
22022202

22032203
Error Object::removeSections(
2204-
bool AllowBrokenLinks, std::function<bool(const SectionBase &)> ToRemove) {
2204+
bool AllowBrokenLinks, std::function<bool(const SectionBase &)> ToRemove, bool VerboseOutput) {
22052205

22062206
auto Iter = std::stable_partition(
22072207
std::begin(Sections), std::end(Sections), [=](const SecPtr &Sec) {
@@ -2236,8 +2236,8 @@ Error Object::removeSections(
22362236
for (auto &RemoveSec : make_range(Iter, std::end(Sections))) {
22372237
for (auto &Segment : Segments)
22382238
Segment->removeSection(RemoveSec.get());
2239-
if (isVerboseEnabled) {
2240-
llvm::outs() << "Removed Section: " << (RemoveSec.get()->Name);
2239+
if (VerboseOutput) {
2240+
outs() << "removed section: " << (RemoveSec.get()->Name);
22412241
}
22422242
RemoveSec->onRemove();
22432243
RemoveSections.insert(RemoveSec.get());
@@ -2282,21 +2282,20 @@ Error Object::replaceSections(
22822282

22832283
if (Error E = removeSections(
22842284
/*AllowBrokenLinks=*/false,
2285-
[=](const SectionBase &Sec) { return FromTo.count(&Sec) > 0; }))
2285+
[=](const SectionBase &Sec) { return FromTo.count(&Sec) > 0; }, false))
22862286
return E;
22872287
llvm::sort(Sections, SectionIndexLess);
22882288
return Error::success();
22892289
}
22902290

22912291
Error Object::removeSymbols(function_ref<bool(const Symbol &)> ToRemove) {
2292-
if (SymbolTable)
2293-
for (const SecPtr &Sec : Sections)
2294-
if (Error E = Sec->removeSymbols(ToRemove)){
2295-
if (isVerboseEnabled){
2296-
llvm::outs() << "Removed Symbols:" << Sec->Name;
2297-
}
2292+
if (SymbolTable){
2293+
for (const SecPtr &Sec : Sections){
2294+
if (Error E = Sec->removeSymbols(ToRemove))
22982295
return E;
2299-
}
2296+
outs() << "removed symbols:" << Sec->Name;
2297+
}
2298+
}
23002299
return Error::success();
23012300
}
23022301

@@ -2583,7 +2582,7 @@ static Error removeUnneededSections(Object &Obj) {
25832582
: Obj.SymbolTable->getStrTab();
25842583
return Obj.removeSections(false, [&](const SectionBase &Sec) {
25852584
return &Sec == Obj.SymbolTable || &Sec == StrTab;
2586-
});
2585+
}, false);
25872586
}
25882587

25892588
template <class ELFT> Error ELFWriter<ELFT>::finalize() {
@@ -2637,7 +2636,7 @@ template <class ELFT> Error ELFWriter<ELFT>::finalize() {
26372636
if (Error E = Obj.removeSections(false /*AllowBrokenLinks*/,
26382637
[this](const SectionBase &Sec) {
26392638
return &Sec == Obj.SectionIndexTable;
2640-
}))
2639+
}, false))
26412640
return E;
26422641
}
26432642
}

llvm/lib/ObjCopy/ELF/ELFObject.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ class SymbolTableSection : public SectionBase {
814814
void setStrTab(StringTableSection *StrTab) { SymbolNames = StrTab; }
815815
void assignIndices();
816816

817+
private:
818+
bool VerboseOutput;
817819
protected:
818820
std::vector<std::unique_ptr<Symbol>> Symbols;
819821
StringTableSection *SymbolNames = nullptr;
@@ -856,6 +858,7 @@ class SymbolTableSection : public SectionBase {
856858
static bool classof(const SectionBase *S) {
857859
return S->OriginalType == ELF::SHT_SYMTAB;
858860
}
861+
bool getVerboseOutput() { return VerboseOutput; }
859862
};
860863

861864
struct Relocation {
@@ -1195,7 +1198,7 @@ class Object {
11951198
uint32_t Flags;
11961199

11971200
bool HadShdrs = true;
1198-
bool isVerboseEnabled = true;
1201+
bool VerboseOutput;
11991202
bool MustBeRelocatable = false;
12001203
StringTableSection *SectionNames = nullptr;
12011204
SymbolTableSection *SymbolTable = nullptr;
@@ -1225,7 +1228,7 @@ class Object {
12251228
ConstRange<Segment> segments() const { return make_pointee_range(Segments); }
12261229

12271230
Error removeSections(bool AllowBrokenLinks,
1228-
std::function<bool(const SectionBase &)> ToRemove);
1231+
std::function<bool(const SectionBase &)> ToRemove, bool VerboseOutput);
12291232
Error compressOrDecompressSections(const CommonConfig &Config);
12301233
Error replaceSections(const DenseMap<SectionBase *, SectionBase *> &FromTo);
12311234
Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove);

0 commit comments

Comments
 (0)