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

Conversation

GermanAizek
Copy link

Reference: #125074

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2025

@llvm/pr-subscribers-llvm-binary-utilities

@llvm/pr-subscribers-backend-directx

Author: Herman Semenoff (GermanAizek)

Changes

Reference: #125074


Full diff: https://github.com/llvm/llvm-project/pull/125089.diff

13 Files Affected:

  • (modified) llvm/include/llvm/Object/Binary.h (+1-1)
  • (modified) llvm/include/llvm/Object/COFFModuleDefinition.h (+1-1)
  • (modified) llvm/include/llvm/Object/DXContainer.h (+1-1)
  • (modified) llvm/include/llvm/Object/ObjectFile.h (+2-2)
  • (modified) llvm/lib/ObjCopy/ELF/ELFObject.cpp (+2-2)
  • (modified) llvm/lib/ObjCopy/ELF/ELFObject.h (+2-2)
  • (modified) llvm/lib/Object/Archive.cpp (+3-3)
  • (modified) llvm/lib/Object/ArchiveWriter.cpp (+1-1)
  • (modified) llvm/lib/Object/Binary.cpp (+1-1)
  • (modified) llvm/lib/Object/COFFModuleDefinition.cpp (+1-1)
  • (modified) llvm/lib/Object/COFFObjectFile.cpp (+4-4)
  • (modified) llvm/lib/Object/DXContainer.cpp (+1-1)
  • (modified) llvm/lib/Object/GOFFObjectFile.cpp (+1-1)
diff --git a/llvm/include/llvm/Object/Binary.h b/llvm/include/llvm/Object/Binary.h
index ce870e25acafe0c..083a8cc0cfeb698 100644
--- a/llvm/include/llvm/Object/Binary.h
+++ b/llvm/include/llvm/Object/Binary.h
@@ -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);
 
diff --git a/llvm/include/llvm/Object/COFFModuleDefinition.h b/llvm/include/llvm/Object/COFFModuleDefinition.h
index a4ed9978dcc0a26..3ccfee8f9142bf3 100644
--- a/llvm/include/llvm/Object/COFFModuleDefinition.h
+++ b/llvm/include/llvm/Object/COFFModuleDefinition.h
@@ -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.
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 19c83ba6c6e85df..78acffda38e0459 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -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; }
 
diff --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h
index 20c0ef5ccfcea20..79e1074a2ae4f37 100644
--- a/llvm/include/llvm/Object/ObjectFile.h
+++ b/llvm/include/llvm/Object/ObjectFile.h
@@ -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);
@@ -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);
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index 45c7ea49b5d938b..7b9b4206a87e625 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -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) {
@@ -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();
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.h b/llvm/lib/ObjCopy/ELF/ELFObject.h
index d8f79a4b1a3cc6e..6506bfbc80eafb9 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.h
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.h
@@ -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,
@@ -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();
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index 92f31c909efd478..2f40e638f8b4167 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -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);
@@ -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;
@@ -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;
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index c61ba868efe60e2..46932ef6d1f4816 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -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.
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp
index 2dfae8ab5d3c641..4b5934cac9903a6 100644
--- a/llvm/lib/Object/Binary.cpp
+++ b/llvm/lib/Object/Binary.cpp
@@ -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());
diff --git a/llvm/lib/Object/COFFModuleDefinition.cpp b/llvm/lib/Object/COFFModuleDefinition.cpp
index 82c18539658e846..1c0fa14d4379119 100644
--- a/llvm/lib/Object/COFFModuleDefinition.cpp
+++ b/llvm/lib/Object/COFFModuleDefinition.cpp
@@ -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) {
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index 242c123665f7632..cf25f393dcb32ab 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -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;
@@ -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
@@ -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;
@@ -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);
 }
 
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 3b1a6203a1f8fcb..f26c0133e24a1c2 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -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);
diff --git a/llvm/lib/Object/GOFFObjectFile.cpp b/llvm/lib/Object/GOFFObjectFile.cpp
index db1e7e704f62e18..b9072fddc5a5221 100644
--- a/llvm/lib/Object/GOFFObjectFile.cpp
+++ b/llvm/lib/Object/GOFFObjectFile.cpp
@@ -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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants