D28094: [ELF] - Implemented support for R_386_PC8/R_386_8 relocations.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 14:13:57 PST 2017


If you apply this patch, your new tests will fail because relocations are
out of range. I think the tests are creating too large values. Can you fix
that?

diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 086b3ad5594..772e22f41a6 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -511,17 +511,24 @@ uint64_t X86TargetInfo::getImplicitAddend(const
uint8_t *Buf,

 void X86TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
                                 uint64_t Val) const {
-  checkInt<32>(Loc, Val, Type);
-
   // R_386_{PC,}{8,16} are not part of the i386 psABI, but they are
   // being used for some 16-bit programs such as boot loaders, so
   // we want to support them.
-  if (Type == R_386_8 || Type == R_386_PC8)
+  switch (Type) {
+  case R_386_8:
+  case R_386_PC8:
+    checkInt<8>(Loc, Val, Type);
     *Loc = Val;
-  else if (Type == R_386_16 || Type == R_386_PC16)
+    break;
+  case R_386_16:
+  case R_386_PC16:
+    checkInt<16>(Loc, Val, Type);
     write16le(Loc, Val);
-  else
+    break;
+  default:
+    checkInt<32>(Loc, Val, Type);
     write32le(Loc, Val);
+  }
 }

On Fri, Jan 27, 2017 at 1:19 AM, George Rimar <grimar at accesssoftek.com>
wrote:

> >>But we already have the same assignment in X86_64TargetInfo<ELFT>::
> relocateOne, so I guess we've accepted that?
> >
> >I guess that means we are not compiling LLD with this and probably other
> useful warnings.
> >Type conversion warnings can be useful for static analysis and I would
> fix that place too instead of accepting.
> >
> >George.
>
> By the way, found we have next code in linkerscript.cpp
>
>
> template <class ELFT>
> static void writeInt(uint8_t *Buf, uint64_t Data, uint64_t Size) {
>   const endianness E = ELFT::TargetEndianness;
>
>   switch (Size) {
>   case 1:
>     *Buf = (uint8_t)Data;​
>
> ​George.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170127/125312a2/attachment.html>


More information about the llvm-commits mailing list