@@ -100,44 +100,41 @@ static std::string getLocation(Ctx &ctx, InputSectionBase &s, const Symbol &sym,
100100void elf::reportRangeError (Ctx &ctx, uint8_t *loc, const Relocation &rel,
101101 const Twine &v, int64_t min, uint64_t max) {
102102 ErrorPlace errPlace = getErrorPlace (ctx, loc);
103- std::string hint;
103+ auto diag = Err (ctx);
104+ diag << errPlace.loc << " relocation " << rel.type
105+ << " out of range: " << v.str () << " is not in [" << min << " , " << max
106+ << ' ]' ;
107+
104108 if (rel.sym ) {
105109 if (!rel.sym ->isSection ())
106- hint = " ; references '" + toStr (ctx, * rel.sym ) + ' \' ' ;
110+ diag << " ; references '" << rel.sym << ' \' ' ;
107111 else if (auto *d = dyn_cast<Defined>(rel.sym ))
108- hint = ( " ; references section '" + d->section ->name + " '" ). str () ;
112+ diag << " ; references section '" << d->section ->name << " '" ;
109113
110114 if (ctx.arg .emachine == EM_X86_64 && rel.type == R_X86_64_PC32 &&
111115 rel.sym ->getOutputSection () &&
112116 (rel.sym ->getOutputSection ()->flags & SHF_X86_64_LARGE)) {
113- hint += " ; R_X86_64_PC32 should not reference a section marked "
117+ diag << " ; R_X86_64_PC32 should not reference a section marked "
114118 " SHF_X86_64_LARGE" ;
115119 }
116120 }
117121 if (!errPlace.srcLoc .empty ())
118- hint += " \n >>> referenced by " + errPlace.srcLoc ;
122+ diag << " \n >>> referenced by " << errPlace.srcLoc ;
119123 if (rel.sym && !rel.sym ->isSection ())
120- hint += getDefinedLocation (ctx, *rel.sym );
124+ diag << getDefinedLocation (ctx, *rel.sym );
121125
122126 if (errPlace.isec && errPlace.isec ->name .starts_with (" .debug" ))
123- hint += " ; consider recompiling with -fdebug-types-section to reduce size "
127+ diag << " ; consider recompiling with -fdebug-types-section to reduce size "
124128 " of debug sections" ;
125-
126- Err (ctx) << errPlace.loc << " relocation " << rel.type
127- << " out of range: " << v.str () << " is not in [" << Twine (min).str ()
128- << " , " << Twine (max).str () << " ]" << hint;
129129}
130130
131131void elf::reportRangeError (Ctx &ctx, uint8_t *loc, int64_t v, int n,
132132 const Symbol &sym, const Twine &msg) {
133- ErrorPlace errPlace = getErrorPlace (ctx, loc);
134- std::string hint;
133+ auto diag = Err (ctx);
134+ diag << getErrorPlace (ctx, loc).loc << msg << " is out of range: " << v
135+ << " is not in [" << llvm::minIntN (n) << " , " << llvm::maxIntN (n) << " ]" ;
135136 if (!sym.getName ().empty ())
136- hint = " ; references '" + toStr (ctx, sym) + ' \' ' +
137- getDefinedLocation (ctx, sym);
138- Err (ctx) << errPlace.loc << msg << " is out of range: " << Twine (v)
139- << " is not in [" << Twine (llvm::minIntN (n)) << " , "
140- << Twine (llvm::maxIntN (n)) << " ]" << hint;
137+ diag << " ; references '" << &sym << ' \' ' << getDefinedLocation (ctx, sym);
141138}
142139
143140// Build a bitmask with one bit set for each 64 subset of RelExpr.
0 commit comments