[llvm] r206138 - MC: check machine magic when applying offset adjustments

Saleem Abdulrasool compnerd at compnerd.org
Sun Apr 13 13:47:56 PDT 2014


Author: compnerd
Date: Sun Apr 13 15:47:55 2014
New Revision: 206138

URL: http://llvm.org/viewvc/llvm-project?rev=206138&view=rev
Log:
MC: check machine magic when applying offset adjustments

The values for the relocation type can (and do) overlap across various
architectures.  When performing an adjustment of the emitted relocation in the
final object file, check that the file magic matches the target for which the
relocation type is valid (e.g. a I386 relocation is only applied to an X86
object file, and an AMD64 relocation is only applied to an X86_64 object file).
This was noticed while adding support for ARM WinCOFF object file emission.

A test case for this is not really possible as the values for REL32 do not
overlap on I386 and AMD64, which is why this was never noticed in practice.  The
ARM WinCOFF emission is not yet ready to merge into the tree.

Modified:
    llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp

Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=206138&r1=206137&r2=206138&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Sun Apr 13 15:47:55 2014
@@ -739,8 +739,10 @@ void WinCOFFObjectWriter::RecordRelocati
 
   // FIXME: Can anyone explain what this does other than adjust for the size
   // of the offset?
-  if (Reloc.Data.Type == COFF::IMAGE_REL_AMD64_REL32 ||
-      Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32)
+  if ((Header.Machine == COFF::IMAGE_FILE_MACHINE_AMD64 &&
+       Reloc.Data.Type == COFF::IMAGE_REL_AMD64_REL32) ||
+      (Header.Machine == COFF::IMAGE_FILE_MACHINE_I386 &&
+       Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32))
     FixedValue += 4;
 
   coff_section->Relocations.push_back(Reloc);





More information about the llvm-commits mailing list