Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[ELFObject] Added conditions to print removed symbols and removed sections #124692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Made Changes
  • Loading branch information
kshitijvp committed Feb 8, 2025
commit 02fb5c0b003a99cdbd36c47c2ffd1ca95ab5db85
1 change: 1 addition & 0 deletions 1 llvm/include/llvm/ObjCopy/CommonConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ struct CommonConfig {
bool StripNonAlloc = false;
bool StripSections = false;
bool StripUnneeded = false;
bool Verbose = false;
bool Weaken = false;
bool DecompressDebugSections = false;

Expand Down
1 change: 1 addition & 0 deletions 1 llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ static Error verifyNoteSection(StringRef Name, endianness Endianness,
// system. The only priority is that keeps/copies overrule removes.
static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
ElfType OutputElfType, Object &Obj) {
Obj.isVerboseEnabled = Config.Verbose;
if (Config.OutputArch) {
Obj.Machine = Config.OutputArch->EMachine;
Obj.OSABI = Config.OutputArch->OSABI;
Expand Down
27 changes: 13 additions & 14 deletions 27 llvm/lib/ObjCopy/ELF/ELFObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ Error SymbolTableSection::removeSymbols(
std::remove_if(std::begin(Symbols) + 1, std::end(Symbols),
[ToRemove](const SymPtr &Sym) {
if (ToRemove(*Sym)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for the braces here (see other comment about coding standards).

dbgs()<<"Symbols Removed:"<<Sym->Name<< "\n";
llvm::outs() << "Symbols Removed:" << Sym->Name<< "\n";
return true;
}
return false;
Expand Down Expand Up @@ -2236,6 +2236,9 @@ Error Object::removeSections(
for (auto &RemoveSec : make_range(Iter, std::end(Sections))) {
for (auto &Segment : Segments)
Segment->removeSection(RemoveSec.get());
if (isVerboseEnabled) {
llvm::outs() << "Removed Section: " << (RemoveSec.get()->Name);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM style doesn't use braces around single-line ifs, typically.

Suggested change
if (isVerboseEnabled) {
llvm::outs() << "Removed Section: " << (RemoveSec.get()->Name);
}
if (isVerboseEnabled)
llvm::outs() << "Removed Section: " << (RemoveSec.get()->Name);

Also, the GNU output uses lower case for its verbose output when printing which files are copied, so it makes sense to print it more like "removed section".

RemoveSec->onRemove();
RemoveSections.insert(RemoveSec.get());
}
Expand All @@ -2255,18 +2258,10 @@ Error Object::removeSections(

// Transfer removed sections into the Object RemovedSections container for use
// later.
for(auto &KeepSec : make_range(std::begin(Sections) , Iter))
{

if (Error E = KeepSec->removeSectionReferences(
AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) {
return RemoveSections.find(Sec) != RemoveSections.end();
}))
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
dbgs()<<"Sections Removed:"<<KeepSec->Name<<'\n';
Sections.erase(Iter, std::end(Sections));
return Error::success();
}
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
// Now finally get rid of them all together.
Sections.erase(Iter, std::end(Sections));
return Error::success();
}

Error Object::replaceSections(
Expand Down Expand Up @@ -2296,8 +2291,12 @@ Error Object::replaceSections(
Error Object::removeSymbols(function_ref<bool(const Symbol &)> ToRemove) {
if (SymbolTable)
for (const SecPtr &Sec : Sections)
if (Error E = Sec->removeSymbols(ToRemove))
if (Error E = Sec->removeSymbols(ToRemove)){
kshitijvp marked this conversation as resolved.
Show resolved Hide resolved
if (isVerboseEnabled){
kshitijvp marked this conversation as resolved.
Show resolved Hide resolved
llvm::outs() << "Removed Symbols:" << Sec->Name;
}
return E;
}
return Error::success();
}

Expand Down
1 change: 1 addition & 0 deletions 1 llvm/lib/ObjCopy/ELF/ELFObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ class Object {
uint32_t Flags;

bool HadShdrs = true;
bool isVerboseEnabled = true;
kshitijvp marked this conversation as resolved.
Show resolved Hide resolved
bool MustBeRelocatable = false;
StringTableSection *SectionNames = nullptr;
SymbolTableSection *SymbolTable = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions 2 llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
OBJCOPY_verify_note_sections, OBJCOPY_no_verify_note_sections, true);

Config.OnlyKeepDebug = InputArgs.hasArg(OBJCOPY_only_keep_debug);
Config.Verbose = InputArgs.hasArg(OBJCOPY_verbose);
ELFConfig.KeepFileSymbols = InputArgs.hasArg(OBJCOPY_keep_file_symbols);
MachOConfig.KeepUndefined = InputArgs.hasArg(OBJCOPY_keep_undefined);
Config.DecompressDebugSections =
Expand Down Expand Up @@ -1586,6 +1587,7 @@ objcopy::parseStripOptions(ArrayRef<const char *> RawArgsArr,
Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu);
MachOConfig.StripSwiftSymbols = InputArgs.hasArg(STRIP_strip_swift_symbols);
Config.OnlyKeepDebug = InputArgs.hasArg(STRIP_only_keep_debug);
Config.Verbose = InputArgs.hasArg(STRIP_verbose);
ELFConfig.KeepFileSymbols = InputArgs.hasArg(STRIP_keep_file_symbols);
MachOConfig.KeepUndefined = InputArgs.hasArg(STRIP_keep_undefined);

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.