[lld] r272034 - Define a helper function to get a relocation name. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 7 22:20:40 PDT 2016


This patch does not change the output even for unknown relocations, but
printing out a number along with a relocation is a good idea. I'll do it
later.

On Tue, Jun 7, 2016 at 10:17 PM, Sean Silva <chisophugis at gmail.com> wrote:

> It would be nice if we still print the number too. For example, I think
> that after this patch, for an unknown relocation we will just print
> "Unknown" and not give even the number.
>
> Even when we have a name, printing the number can be convenient too (to
> e.g. find it in a hex editor etc. without doing an extra lookup).
>
> -- Sean Silva
>
> On Tue, Jun 7, 2016 at 11:10 AM, Rui Ueyama via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: ruiu
>> Date: Tue Jun  7 13:10:12 2016
>> New Revision: 272034
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=272034&view=rev
>> Log:
>> Define a helper function to get a relocation name. NFC.
>>
>> Modified:
>>     lld/trunk/ELF/Target.cpp
>>
>> Modified: lld/trunk/ELF/Target.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=272034&r1=272033&r2=272034&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Target.cpp (original)
>> +++ lld/trunk/ELF/Target.cpp Tue Jun  7 13:10:12 2016
>> @@ -47,36 +47,36 @@ TargetInfo *Target;
>>
>>  static void or32le(uint8_t *P, int32_t V) { write32le(P, read32le(P) |
>> V); }
>>
>> +static StringRef getRelName(uint32_t Type) {
>> +  return getELFRelocationTypeName(Config->EMachine, Type);
>> +}
>> +
>>  template <unsigned N> static void checkInt(int64_t V, uint32_t Type) {
>>    if (isInt<N>(V))
>>      return;
>> -  StringRef S = getELFRelocationTypeName(Config->EMachine, Type);
>> -  error("relocation " + S + " out of range");
>> +  error("relocation " + getRelName(Type) + " out of range");
>>  }
>>
>>  template <unsigned N> static void checkUInt(uint64_t V, uint32_t Type) {
>>    if (isUInt<N>(V))
>>      return;
>> -  StringRef S = getELFRelocationTypeName(Config->EMachine, Type);
>> -  error("relocation " + S + " out of range");
>> +  error("relocation " + getRelName(Type) + " out of range");
>>  }
>>
>>  template <unsigned N> static void checkIntUInt(uint64_t V, uint32_t
>> Type) {
>>    if (isInt<N>(V) || isUInt<N>(V))
>>      return;
>> -  StringRef S = getELFRelocationTypeName(Config->EMachine, Type);
>> -  error("relocation " + S + " out of range");
>> +  error("relocation " + getRelName(Type) + " out of range");
>>  }
>>
>>  template <unsigned N> static void checkAlignment(uint64_t V, uint32_t
>> Type) {
>>    if ((V & (N - 1)) == 0)
>>      return;
>> -  StringRef S = getELFRelocationTypeName(Config->EMachine, Type);
>> -  error("improper alignment for relocation " + S);
>> +  error("improper alignment for relocation " + getRelName(Type));
>>  }
>>
>>  static void warnDynRel(uint32_t Type) {
>> -  error("relocation " + getELFRelocationTypeName(Config->EMachine, Type)
>> +
>> +  error("relocation " + getRelName(Type) +
>>          " cannot be used when making a shared object; recompile with
>> -fPIC.");
>>  }
>>
>> @@ -617,10 +617,8 @@ void X86_64TargetInfo::writePlt(uint8_t
>>  }
>>
>>  uint32_t X86_64TargetInfo::getDynRel(uint32_t Type) const {
>> -  if (Type == R_X86_64_PC32 || Type == R_X86_64_32)
>> -    if (Config->Shared)
>> -      error(getELFRelocationTypeName(EM_X86_64, Type) +
>> -            " cannot be a dynamic relocation");
>> +  if (Config->Shared && (Type == R_X86_64_PC32 || Type == R_X86_64_32))
>> +    error(getRelName(Type) + " cannot be a dynamic relocation");
>>    return Type;
>>  }
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160607/e7ff6e43/attachment.html>


More information about the llvm-commits mailing list