[lld] r247768 - [elf2] Simplify overflow checks.

Michael Spencer via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 19:27:19 PDT 2015


On Tue, Sep 15, 2015 at 7:02 PM, Michael J. Spencer via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: mspencer
> Date: Tue Sep 15 21:02:04 2015
> New Revision: 247768
>
> URL: http://llvm.org/viewvc/llvm-project?rev=247768&view=rev
> Log:
> [elf2] Simplify overflow checks.
>
> Modified:
>     lld/trunk/ELF/Writer.cpp
>     lld/trunk/test/elf2/relocation-errors.s
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247768&r1=247767&r2=247768&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Tue Sep 15 21:02:04 2015
> @@ -14,7 +14,6 @@
>  #include "Symbols.h"
>  #include "SymbolTable.h"
>
> -#include "llvm/ADT/APInt.h"
>  #include "llvm/ADT/DenseMap.h"
>  #include "llvm/ADT/STLExtras.h"
>  #include "llvm/MC/StringTableBuilder.h"
> @@ -502,18 +501,13 @@ template <class ELFT> void OutputSection
>            break;
>          case llvm::ELF::R_X86_64_32: {
>          case llvm::ELF::R_X86_64_32S:
> -          APInt VA(64, SymVA);
> -          APInt Addend(64, RI.r_addend, true);
> -          APInt Result64 = VA + Addend;
> -          APInt Result = Result64.trunc(32);
> -          if (Type == llvm::ELF::R_X86_64_32) {
> -            if (Result.zext(64) != Result64)
> -              error("Relocation out of range");
> -          } else
> -            if (Result.sext(64) != Result64)
> -              error("R_X86_64_32S out of range");
> +          uint64_t VA = SymVA + RI.r_addend;
> +          if (Type == llvm::ELF::R_X86_64_32 && !isUInt<32>(VA))
> +            error("R_X86_64_32 out of range");
> +          else if (!isInt<32>(VA))
> +            error("R_X86_64_32S out of range");
>
> -          support::endian::write32le(Location, Result.getZExtValue());
> +          support::endian::write32le(Location, VA);
>            break;
>          }
>          default:
>
> Modified: lld/trunk/test/elf2/relocation-errors.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation-errors.s?rev=247768&r1=247767&r2=247768&view=diff
> ==============================================================================
> --- lld/trunk/test/elf2/relocation-errors.s (original)
> +++ lld/trunk/test/elf2/relocation-errors.s Tue Sep 15 21:02:04 2015
> @@ -7,4 +7,4 @@
>  _start:
>    movl $big, %edx
>
> -#CHECK: Relocation out of range
> +#CHECK: R_X86_64_32 out of range
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

Commit message is wrong here. This is the truncation check from the
spec. It doesn't check for 64 bit overflow. ld doesn't either, but we
probably should, however that will be a different test.

- Michael Spencer


More information about the llvm-commits mailing list