Skip to content

Commit

Permalink
MCAssembler: Move Symvers to ELFObjectWriter
Browse files Browse the repository at this point in the history
Similar to c473e75
  • Loading branch information
MaskRay committed Jul 23, 2024
1 parent adea9f9 commit 9e97f80
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
9 changes: 0 additions & 9 deletions llvm/include/llvm/MC/MCAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,6 @@ class MCAssembler {
handleFixup(MCFragment &F, const MCFixup &Fixup, const MCSubtargetInfo *STI);

public:
struct Symver {
SMLoc Loc;
const MCSymbol *Sym;
StringRef Name;
// True if .symver *, *@@@* or .symver *, *, remove.
bool KeepOriginalSym;
};
std::vector<Symver> Symvers;

/// Construct a new assembler instance.
//
// FIXME: How are we going to parameterize this? Two obvious options are stay
Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/MC/MCELFObjectWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_MC_MCELFOBJECTWRITER_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSectionELF.h"
Expand Down Expand Up @@ -163,6 +164,15 @@ class ELFObjectWriter : public MCObjectWriter {
bool SeenGnuAbi = false;
std::optional<uint8_t> OverrideABIVersion;

struct Symver {
SMLoc Loc;
const MCSymbol *Sym;
StringRef Name;
// True if .symver *, *@@@* or .symver *, *, remove.
bool KeepOriginalSym;
};
SmallVector<Symver, 0> Symvers;

ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW)
: TargetObjectWriter(std::move(MOTW)) {}

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/MC/ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ void ELFObjectWriter::reset() {
OverrideABIVersion.reset();
Relocations.clear();
Renames.clear();
Symvers.clear();
MCObjectWriter::reset();
}

Expand All @@ -1172,7 +1173,7 @@ bool ELFObjectWriter::hasRelocationAddend() const {
void ELFObjectWriter::executePostLayoutBinding(MCAssembler &Asm) {
// The presence of symbol versions causes undefined symbols and
// versions declared with @@@ to be renamed.
for (const MCAssembler::Symver &S : Asm.Symvers) {
for (const Symver &S : Symvers) {
StringRef AliasName = S.Name;
const auto &Symbol = cast<MCSymbolELF>(*S.Sym);
size_t Pos = AliasName.find('@');
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
void MCELFStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
StringRef Name,
bool KeepOriginalSym) {
getAssembler().Symvers.push_back(MCAssembler::Symver{
getWriter().Symvers.push_back(ELFObjectWriter::Symver{
getStartTokLoc(), OriginalSym, Name, KeepOriginalSym});
}

Expand Down

0 comments on commit 9e97f80

Please sign in to comment.