Skip to content

[OBJECT][OBJCOPY] Added const reference for params with size >= 16 bytes #125089

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 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/Binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ DEFINE_ISA_CONVERSION_FUNCTIONS(Binary, LLVMBinaryRef)
/// Create a Binary from Source, autodetecting the file type.
///
/// @param Source The data to create the Binary from.
Expected<std::unique_ptr<Binary>> createBinary(MemoryBufferRef Source,
Expected<std::unique_ptr<Binary>> createBinary(const MemoryBufferRef &Source,
LLVMContext *Context = nullptr,
bool InitContent = true);

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/COFFModuleDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct COFFModuleDefinition {
};

Expected<COFFModuleDefinition>
parseCOFFModuleDefinition(MemoryBufferRef MB, COFF::MachineTypes Machine,
parseCOFFModuleDefinition(const MemoryBufferRef &MB, COFF::MachineTypes Machine,
bool MingwDef = false, bool AddUnderscores = true);

} // End namespace object.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class DXContainer {
PartIterator end() const { return PartIterator(*this, PartOffsets.end()); }

StringRef getData() const { return Data.getBuffer(); }
static Expected<DXContainer> create(MemoryBufferRef Object);
static Expected<DXContainer> create(const MemoryBufferRef &Object);

const dxbc::Header &getHeader() const { return Header; }

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Object/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class ObjectFile : public SymbolicFile {
}

static Expected<std::unique_ptr<COFFObjectFile>>
createCOFFObjectFile(MemoryBufferRef Object);
createCOFFObjectFile(const MemoryBufferRef &Object);

static Expected<std::unique_ptr<ObjectFile>>
createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType);
Expand All @@ -396,7 +396,7 @@ class ObjectFile : public SymbolicFile {
size_t MachOFilesetEntryOffset = 0);

static Expected<std::unique_ptr<ObjectFile>>
createGOFFObjectFile(MemoryBufferRef Object);
createGOFFObjectFile(const MemoryBufferRef &Object);

static Expected<std::unique_ptr<WasmObjectFile>>
createWasmObjectFile(MemoryBufferRef Object);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ObjCopy/ELF/ELFObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ void SymbolTableSection::assignIndices() {
}
}

void SymbolTableSection::addSymbol(Twine Name, uint8_t Bind, uint8_t Type,
void SymbolTableSection::addSymbol(const Twine &Name, uint8_t Bind, uint8_t Type,
SectionBase *DefinedIn, uint64_t Value,
uint8_t Visibility, uint16_t Shndx,
uint64_t SymbolSize) {
Expand Down Expand Up @@ -1680,7 +1680,7 @@ static Error initRelocations(RelocationSection *Relocs, T RelRange) {
}

Expected<SectionBase *> SectionTableRef::getSection(uint32_t Index,
Twine ErrMsg) {
const Twine &ErrMsg) {
if (Index == SHN_UNDEF || Index > Sections.size())
return createStringError(errc::invalid_argument, ErrMsg);
return Sections[Index - 1].get();
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ObjCopy/ELF/ELFObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SectionTableRef {
iterator end() const { return iterator(Sections.data() + Sections.size()); }
size_t size() const { return Sections.size(); }

Expected<SectionBase *> getSection(uint32_t Index, Twine ErrMsg);
Expected<SectionBase *> getSection(uint32_t Index, const Twine &ErrMsg);

template <class T>
Expected<T *> getSectionOfType(uint32_t Index, Twine IndexErrMsg,
Expand Down Expand Up @@ -825,7 +825,7 @@ class SymbolTableSection : public SectionBase {
public:
SymbolTableSection() { Type = OriginalType = ELF::SHT_SYMTAB; }

void addSymbol(Twine Name, uint8_t Bind, uint8_t Type, SectionBase *DefinedIn,
void addSymbol(const Twine &Name, uint8_t Bind, uint8_t Type, SectionBase *DefinedIn,
uint64_t Value, uint8_t Visibility, uint16_t Shndx,
uint64_t SymbolSize);
void prepareForLayout();
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Object/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using namespace llvm::support::endian;

void Archive::anchor() {}

static Error malformedError(Twine Msg) {
static Error malformedError(const Twine &Msg) {
std::string StringMsg = "truncated or malformed archive (" + Msg.str() + ")";
return make_error<GenericBinaryError>(std::move(StringMsg),
object_error::parse_failed);
Expand Down Expand Up @@ -177,7 +177,7 @@ Expected<StringRef> ArchiveMemberHeader::getRawName() const {
}

Expected<uint64_t>
getArchiveMemberDecField(Twine FieldName, const StringRef RawField,
getArchiveMemberDecField(const Twine &FieldName, const StringRef RawField,
const Archive *Parent,
const AbstractArchiveMemberHeader *MemHeader) {
uint64_t Value;
Expand All @@ -195,7 +195,7 @@ getArchiveMemberDecField(Twine FieldName, const StringRef RawField,
}

Expected<uint64_t>
getArchiveMemberOctField(Twine FieldName, const StringRef RawField,
getArchiveMemberOctField(const Twine &FieldName, const StringRef RawField,
const Archive *Parent,
const AbstractArchiveMemberHeader *MemHeader) {
uint64_t Value;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/ArchiveWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static uint64_t computeHeadersSize(object::Archive::Kind Kind,
}

static Expected<std::unique_ptr<SymbolicFile>>
getSymbolicFile(MemoryBufferRef Buf, LLVMContext &Context,
getSymbolicFile(const MemoryBufferRef &Buf, LLVMContext &Context,
object::Archive::Kind Kind, function_ref<void(Error)> Warn) {
const file_magic Type = identify_magic(Buf.getBuffer());
// Don't attempt to read non-symbolic file types.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/Binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ StringRef Binary::getFileName() const { return Data.getBufferIdentifier(); }

MemoryBufferRef Binary::getMemoryBufferRef() const { return Data; }

Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
Expected<std::unique_ptr<Binary>> object::createBinary(const MemoryBufferRef &Buffer,
LLVMContext *Context,
bool InitContent) {
file_magic Type = identify_magic(Buffer.getBuffer());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/COFFModuleDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class Parser {
bool AddUnderscores;
};

Expected<COFFModuleDefinition> parseCOFFModuleDefinition(MemoryBufferRef MB,
Expected<COFFModuleDefinition> parseCOFFModuleDefinition(const MemoryBufferRef &MB,
MachineTypes Machine,
bool MingwDef,
bool AddUnderscores) {
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Object/COFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using support::ulittle64_t;
using support::little16_t;

// Returns false if size is greater than the buffer size. And sets ec.
static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size) {
static bool checkSize(const MemoryBufferRef &M, std::error_code &EC, uint64_t Size) {
if (M.getBufferSize() < Size) {
EC = object_error::unexpected_eof;
return false;
Expand Down Expand Up @@ -353,7 +353,7 @@ bool COFFObjectFile::isSectionVirtual(DataRefImpl Ref) const {
}

static uint32_t getNumberOfRelocations(const coff_section *Sec,
MemoryBufferRef M, const uint8_t *base) {
const MemoryBufferRef &M, const uint8_t *base) {
// The field for the number of relocations in COFF section table is only
// 16-bit wide. If a section has more than 65535 relocations, 0xFFFF is set to
// NumberOfRelocations field, and the actual relocation count is stored in the
Expand All @@ -373,7 +373,7 @@ static uint32_t getNumberOfRelocations(const coff_section *Sec,
}

static const coff_relocation *
getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) {
getFirstReloc(const coff_section *Sec, const MemoryBufferRef &M, const uint8_t *Base) {
uint64_t NumRelocs = getNumberOfRelocations(Sec, M, Base);
if (!NumRelocs)
return nullptr;
Expand Down Expand Up @@ -1893,7 +1893,7 @@ Error ImportedSymbolRef::getOrdinal(uint16_t &Result) const {
}

Expected<std::unique_ptr<COFFObjectFile>>
ObjectFile::createCOFFObjectFile(MemoryBufferRef Object) {
ObjectFile::createCOFFObjectFile(const MemoryBufferRef &Object) {
return COFFObjectFile::create(Object);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/DXContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Error DXContainer::parsePartOffsets() {
return Error::success();
}

Expected<DXContainer> DXContainer::create(MemoryBufferRef Object) {
Expected<DXContainer> DXContainer::create(const MemoryBufferRef &Object) {
DXContainer Container(Object);
if (Error Err = Container.parseHeader())
return std::move(Err);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/GOFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace llvm::object;
using namespace llvm;

Expected<std::unique_ptr<ObjectFile>>
ObjectFile::createGOFFObjectFile(MemoryBufferRef Object) {
ObjectFile::createGOFFObjectFile(const MemoryBufferRef &Object) {
Error Err = Error::success();
std::unique_ptr<GOFFObjectFile> Ret(new GOFFObjectFile(Object, Err));
if (Err)
Expand Down