[PATCH] D75527: [yaml2obj] - Add `ELFYAML::YAMLInt` to fix how we parse a relocation `Addend` key.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 06:05:01 PST 2020


grimar added a comment.

In D75527#1907129 <https://reviews.llvm.org/D75527#1907129>, @jhenderson wrote:

> My inclination is that yaml2obj should support both signed and unsigned variants of both hex and decimal numbers, if feasible.


I'd like to clarify what you mean.

Are you ok to support `Addend: -4294967295`? (4294967295 == 0xFFFFFFFF) for 32 bit ELF
and `Addend: -18446744073709551615` (18446744073709551615 == 0xFFFFFFFFFFFFFFFF) for 64-bit one?
(it is the same as `Addend: 1`)

Looks like that because we are not going to restrict
`Addend: -0xFFFFFFFF` or `Addend: -0xFFFFFFFFFFFFFFFF` it seems.

If so, then this patch can be a bit simpler, we can probably check `-` and always read value as unsigned int64.
I.e. both:

- [-18446744073709551615, 18446744073709551615]
- [       -0xFFFFFFFFFFFFFFFF,        0xFFFFFFFFFFFFFFFF]

  StringRef ScalarTraits<ELFYAML::YAMLInt>::input(StringRef Scalar, void *Ctx,
                                                  ELFYAML::YAMLInt &Val) {
    const bool Is64 = static_cast<ELFYAML::Object *>(Ctx)->Header.Class ==
                      ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
    StringRef ErrMsg = "invalid number";
  
    bool IsNegative = Scalar.front() == '-';
    if (IsNegative)
      Scalar = Scalar.drop_front();
  
    unsigned long long UInt;
    if (getAsUnsignedInteger(Scalar, /*Radix=*/0, UInt))
      return ErrMsg;
  
    // For a 32-bit target we allow values in a range of a uint32_t.
    if (!Is64 && (UInt > UINT32_MAX))
      return ErrMsg;
  
    Val = IsNegative ? (-UInt) : UInt;
    return "";
  }

Did you mean something like that?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75527/new/

https://reviews.llvm.org/D75527





More information about the llvm-commits mailing list