summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-objcopy')
-rw-r--r--llvm/tools/llvm-objcopy/ObjcopyOpts.td2
-rw-r--r--llvm/tools/llvm-objcopy/Object.cpp16
-rw-r--r--llvm/tools/llvm-objcopy/Object.h16
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp9
4 files changed, 4 insertions, 39 deletions
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index e7c7541a32c..9d1fb19c40c 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -90,5 +90,3 @@ def K : JoinedOrSeparate<["-"], "K">,
Alias<keep_symbol>;
def only_keep_debug : Flag<["-", "--"], "only-keep-debug">,
HelpText<"Currently ignored. Only for compaitability with GNU objcopy.">;
-def strip_unneeded : Flag<["-", "--"], "strip-unneeded">,
- HelpText<"Remove all symbols not needed by relocations">;
diff --git a/llvm/tools/llvm-objcopy/Object.cpp b/llvm/tools/llvm-objcopy/Object.cpp
index bd728270fb7..efb3207aa8d 100644
--- a/llvm/tools/llvm-objcopy/Object.cpp
+++ b/llvm/tools/llvm-objcopy/Object.cpp
@@ -185,7 +185,6 @@ void SymbolTableSection::addSymbol(StringRef Name, uint8_t Bind, uint8_t Type,
Sym.Visibility = Visibility;
Sym.Size = Sz;
Sym.Index = Symbols.size();
- Sym.ReferenceCount = 0;
Symbols.emplace_back(llvm::make_unique<Symbol>(Sym));
Size += this->EntrySize;
}
@@ -256,11 +255,6 @@ const Symbol *SymbolTableSection::getSymbolByIndex(uint32_t Index) const {
return Symbols[Index].get();
}
-Symbol *SymbolTableSection::getSymbolByIndex(uint32_t Index) {
- return const_cast<Symbol *>(
- static_cast<const SymbolTableSection *>(this)->getSymbolByIndex(Index));
-}
-
template <class ELFT>
void ELFSectionWriter<ELFT>::visit(const SymbolTableSection &Sec) {
uint8_t *Buf = Out.getBufferStart();
@@ -350,12 +344,6 @@ void RelocationSection::accept(SectionVisitor &Visitor) const {
Visitor.visit(*this);
}
-RelocationSection::~RelocationSection() {
- for (auto &Rel : Relocations) {
- --Rel.RelocSymbol->ReferenceCount;
- }
-}
-
void RelocationSection::removeSymbols(
function_ref<bool(const Symbol &)> ToRemove) {
for (const Relocation &Reloc : Relocations)
@@ -659,9 +647,7 @@ void initRelocations(RelocationSection *Relocs, SymbolTableSection *SymbolTable,
ToAdd.Offset = Rel.r_offset;
getAddend(ToAdd.Addend, Rel);
ToAdd.Type = Rel.getType(false);
- Symbol *Sym = SymbolTable->getSymbolByIndex(Rel.getSymbol(false));
- ++Sym->ReferenceCount;
- ToAdd.RelocSymbol = Sym;
+ ToAdd.RelocSymbol = SymbolTable->getSymbolByIndex(Rel.getSymbol(false));
Relocs->addRelocation(ToAdd);
}
}
diff --git a/llvm/tools/llvm-objcopy/Object.h b/llvm/tools/llvm-objcopy/Object.h
index 74ef5a7ebcc..ac384c1fdfe 100644
--- a/llvm/tools/llvm-objcopy/Object.h
+++ b/llvm/tools/llvm-objcopy/Object.h
@@ -344,7 +344,6 @@ struct Symbol {
uint8_t Type;
uint64_t Value;
uint8_t Visibility;
- uint32_t ReferenceCount;
uint16_t getShndx() const;
};
@@ -368,7 +367,6 @@ public:
void addSymbolNames();
const SectionBase *getStrTab() const { return SymbolNames; }
const Symbol *getSymbolByIndex(uint32_t Index) const;
- Symbol *getSymbolByIndex(uint32_t Index);
void updateSymbols(function_ref<void(Symbol &)> Callable);
void removeSectionReferences(const SectionBase *Sec) override;
@@ -383,7 +381,7 @@ public:
};
struct Relocation {
- Symbol *RelocSymbol = nullptr;
+ const Symbol *RelocSymbol = nullptr;
uint64_t Offset;
uint64_t Addend;
uint32_t Type;
@@ -434,7 +432,6 @@ class RelocationSection
std::vector<Relocation> Relocations;
public:
- ~RelocationSection();
void addRelocation(Relocation Rel) { Relocations.push_back(Rel); }
void accept(SectionVisitor &Visitor) const override;
void removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
@@ -452,7 +449,7 @@ public:
class GroupSection : public SectionBase {
MAKE_SEC_WRITER_FRIEND
const SymbolTableSection *SymTab = nullptr;
- Symbol *Sym = nullptr;
+ const Symbol *Sym = nullptr;
ELF::Elf32_Word FlagWord;
SmallVector<SectionBase *, 3> GroupMembers;
@@ -462,16 +459,9 @@ public:
ArrayRef<uint8_t> Contents;
explicit GroupSection(ArrayRef<uint8_t> Data) : Contents(Data) {}
- ~GroupSection() {
- if (Sym)
- --Sym->ReferenceCount;
- }
void setSymTab(const SymbolTableSection *SymTabSec) { SymTab = SymTabSec; }
- void setSymbol(Symbol *S) {
- Sym = S;
- ++Sym->ReferenceCount;
- }
+ void setSymbol(const Symbol *S) { Sym = S; }
void setFlagWord(ELF::Elf32_Word W) { FlagWord = W; }
void addMember(SectionBase *Sec) { GroupMembers.push_back(Sec); }
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 36b1b64e35d..99cc1039f7d 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -156,7 +156,6 @@ struct CopyConfig {
bool StripSections = false;
bool StripNonAlloc = false;
bool StripDWO = false;
- bool StripUnneeded = false;
bool ExtractDWO = false;
bool LocalizeHidden = false;
bool Weaken = false;
@@ -390,13 +389,6 @@ void HandleArgs(const CopyConfig &Config, Object &Obj, const Reader &Reader,
return true;
}
- // TODO: We might handle the 'null symbol' in a different way
- // by probably handling it the same way as we handle 'null section' ?
- if (Config.StripUnneeded && !Sym.ReferenceCount && Sym.Index != 0 &&
- (Sym.Binding == STB_LOCAL || Sym.getShndx() == SHN_UNDEF) &&
- Sym.Type != STT_FILE && Sym.Type != STT_SECTION)
- return true;
-
return false;
});
}
@@ -487,7 +479,6 @@ CopyConfig ParseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
Config.StripDWO = InputArgs.hasArg(OBJCOPY_strip_dwo);
Config.StripSections = InputArgs.hasArg(OBJCOPY_strip_sections);
Config.StripNonAlloc = InputArgs.hasArg(OBJCOPY_strip_non_alloc);
- Config.StripUnneeded = InputArgs.hasArg(OBJCOPY_strip_unneeded);
Config.ExtractDWO = InputArgs.hasArg(OBJCOPY_extract_dwo);
Config.LocalizeHidden = InputArgs.hasArg(OBJCOPY_localize_hidden);
Config.Weaken = InputArgs.hasArg(OBJCOPY_weaken);
OpenPOWER on IntegriCloud