forked from OSchip/llvm-project
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. llvm-svn: 206138
This commit is contained in:
parent
4bb54d51c8
commit
2c08051cc5
|
@ -739,8 +739,10 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
|||
|
||||
// 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);
|
||||
|
|
Loading…
Reference in New Issue