@@ -100,44 +100,41 @@ static std::string getLocation(Ctx &ctx, InputSectionBase &s, const Symbol &sym,
100
100
void elf::reportRangeError (Ctx &ctx, uint8_t *loc, const Relocation &rel,
101
101
const Twine &v, int64_t min, uint64_t max) {
102
102
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
+
104
108
if (rel.sym ) {
105
109
if (!rel.sym ->isSection ())
106
- hint = " ; references '" + toStr (ctx, * rel.sym ) + ' \' ' ;
110
+ diag << " ; references '" << rel.sym << ' \' ' ;
107
111
else if (auto *d = dyn_cast<Defined>(rel.sym ))
108
- hint = ( " ; references section '" + d->section ->name + " '" ). str () ;
112
+ diag << " ; references section '" << d->section ->name << " '" ;
109
113
110
114
if (ctx.arg .emachine == EM_X86_64 && rel.type == R_X86_64_PC32 &&
111
115
rel.sym ->getOutputSection () &&
112
116
(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 "
114
118
" SHF_X86_64_LARGE" ;
115
119
}
116
120
}
117
121
if (!errPlace.srcLoc .empty ())
118
- hint += " \n >>> referenced by " + errPlace.srcLoc ;
122
+ diag << " \n >>> referenced by " << errPlace.srcLoc ;
119
123
if (rel.sym && !rel.sym ->isSection ())
120
- hint += getDefinedLocation (ctx, *rel.sym );
124
+ diag << getDefinedLocation (ctx, *rel.sym );
121
125
122
126
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 "
124
128
" 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;
129
129
}
130
130
131
131
void elf::reportRangeError (Ctx &ctx, uint8_t *loc, int64_t v, int n,
132
132
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) << " ]" ;
135
136
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);
141
138
}
142
139
143
140
// Build a bitmask with one bit set for each 64 subset of RelExpr.
0 commit comments