[lld] 47e6673 - [ELF] Replace toString(RelType) with operator<< while using ELFSyncStream

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 10:12:14 PST 2024


Author: Fangrui Song
Date: 2024-11-16T10:12:08-08:00
New Revision: 47e6673006a0f27b39867f49b25bddc4e1116cd2

URL: https://github.com/llvm/llvm-project/commit/47e6673006a0f27b39867f49b25bddc4e1116cd2
DIFF: https://github.com/llvm/llvm-project/commit/47e6673006a0f27b39867f49b25bddc4e1116cd2.diff

LOG: [ELF] Replace toString(RelType) with operator<< while using ELFSyncStream

Added: 
    

Modified: 
    lld/ELF/Arch/LoongArch.cpp
    lld/ELF/Arch/RISCV.cpp
    lld/ELF/Relocations.cpp
    lld/ELF/Target.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index a874c7e909b6bd..328e6bab244413 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -775,8 +775,8 @@ static bool relax(Ctx &ctx, InputSection &sec) {
       // If we can't satisfy this alignment, we've found a bad input.
       if (LLVM_UNLIKELY(static_cast<int32_t>(remove) < 0)) {
         Err(ctx) << getErrorLoc(ctx, (const uint8_t *)loc)
-                 << "insufficient padding bytes for " << lld::toString(r.type)
-                 << ": " << Twine(allBytes) << " bytes available for "
+                 << "insufficient padding bytes for " << r.type << ": "
+                 << Twine(allBytes) << " bytes available for "
                  << "requested alignment of " << Twine(align) << " bytes";
         remove = 0;
       }

diff  --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index ca3a8f9f05e78c..146a875a65c270 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -662,7 +662,7 @@ void RISCV::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
           if (overwriteULEB128(loc, val) >= 0x80)
             Err(ctx) << sec.getLocation(rel.offset) << ": ULEB128 value "
                      << Twine(val) << " exceeds available space; references '"
-                     << lld::toString(*rel.sym) << "'";
+                     << rel.sym << "'";
           ++i;
           continue;
         }
@@ -833,8 +833,8 @@ static bool relax(Ctx &ctx, InputSection &sec) {
       // If we can't satisfy this alignment, we've found a bad input.
       if (LLVM_UNLIKELY(static_cast<int32_t>(remove) < 0)) {
         Err(ctx) << getErrorLoc(ctx, (const uint8_t *)loc)
-                 << "insufficient padding bytes for " << lld::toString(r.type)
-                 << ": " << Twine(r.addend)
+                 << "insufficient padding bytes for " << r.type << ": "
+                 << Twine(r.addend)
                  << " bytes available "
                     "for requested alignment of "
                  << Twine(align) << " bytes";

diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 6ef91af51568d4..697e04d21aab09 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -123,7 +123,7 @@ void elf::reportRangeError(Ctx &ctx, uint8_t *loc, const Relocation &rel,
     hint += "; consider recompiling with -fdebug-types-section to reduce size "
             "of debug sections";
 
-  Err(ctx) << errPlace.loc << "relocation " << lld::toString(rel.type)
+  Err(ctx) << errPlace.loc << "relocation " << rel.type
            << " out of range: " << v.str() << " is not in [" << Twine(min).str()
            << ", " << Twine(max).str() << "]" << hint;
 }

diff  --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index baf4f48de12ee8..af6024ef054a3f 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -255,6 +255,8 @@ void setTarget(Ctx &);
 
 template <class ELFT> bool isMipsPIC(const Defined *sym);
 
+const ELFSyncStream &operator<<(const ELFSyncStream &, RelType);
+
 void reportRangeError(Ctx &, uint8_t *loc, const Relocation &rel,
                       const Twine &v, int64_t min, uint64_t max);
 void reportRangeError(Ctx &ctx, uint8_t *loc, int64_t v, int n,
@@ -288,9 +290,9 @@ inline void checkIntUInt(Ctx &ctx, uint8_t *loc, uint64_t v, int n,
 inline void checkAlignment(Ctx &ctx, uint8_t *loc, uint64_t v, int n,
                            const Relocation &rel) {
   if ((v & (n - 1)) != 0)
-    error(getErrorLoc(ctx, loc) + "improper alignment for relocation " +
-          lld::toString(rel.type) + ": 0x" + llvm::utohexstr(v) +
-          " is not aligned to " + Twine(n) + " bytes");
+    Err(ctx) << getErrorLoc(ctx, loc) << "improper alignment for relocation "
+             << rel.type << ": 0x" << llvm::utohexstr(v)
+             << " is not aligned to " << Twine(n) << " bytes";
 }
 
 // Endianness-aware read/write.
@@ -327,8 +329,6 @@ inline uint64_t overwriteULEB128(uint8_t *bufLoc, uint64_t val) {
   *bufLoc = val;
   return val;
 }
-
-const ELFSyncStream &operator<<(const ELFSyncStream &, RelType);
 } // namespace elf
 } // namespace lld
 


        


More information about the llvm-commits mailing list