[llvm] r315964 - [ExecutionEngine] Correct the size of a write in a COFF i386 relocation

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 18:41:14 PDT 2017


Author: smeenai
Date: Mon Oct 16 18:41:14 2017
New Revision: 315964

URL: http://llvm.org/viewvc/llvm-project?rev=315964&view=rev
Log:
[ExecutionEngine] Correct the size of a write in a COFF i386 relocation

We want to be writing a 32bit value, so we should be writing 4 bytes
instead of 2.

Patch by Alex Langford <apl at fb.com>.

Differential Revision: https://reviews.llvm.org/D38872

Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
    llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h?rev=315964&r1=315963&r2=315964&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h Mon Oct 16 18:41:14 2017
@@ -209,7 +209,7 @@ public:
       DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
                    << " RelType: IMAGE_REL_I386_SECREL Value: " << RE.Addend
                    << '\n');
-      writeBytesUnaligned(RE.Addend, Target, 2);
+      writeBytesUnaligned(RE.Addend, Target, 4);
       break;
     default:
       llvm_unreachable("unsupported relocation type");

Modified: llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s?rev=315964&r1=315963&r2=315964&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s (original)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s Mon Oct 16 18:41:14 2017
@@ -49,11 +49,6 @@ __imp__ExitProcess:
 	.long "_ExitProcess at 4"			// IMAGE_REL_I386_DIR32
 # rtdyld-check: *{4}__imp__ExitProcess = 0xffffffff
 
-	.global string
-	.align 1
-string:
-	.asciz "Hello World!\n"
-
 	.global relocations
 relocations:
 rel5:
@@ -63,8 +58,8 @@ rel6:
 # rtdyld-check: *{2}rel6 = 1
 	.secidx __imp__OutputDebugStringA	// IMAGE_REL_I386_SECTION
 rel7:
-# rtdyld-check: *{4}rel7 = relocations - section_addr(COFF_i386.s.tmp.obj, .data)
-	.secrel32 relocations			// IMAGE_REL_I386_SECREL
+# rtdyld-check: *{4}rel7 = string - section_addr(COFF_i386.s.tmp.obj, .data)
+	.secrel32 string			// IMAGE_REL_I386_SECREL
 
 # Test that addends work.
 rel8:
@@ -79,3 +74,12 @@ rel10:
 rel11:
 # rtdyld-check: *{4}rel11 = string - section_addr(COFF_i386.s.tmp.obj, .data) + 1
 	.long string at SECREL32+1			// IMAGE_REL_I386_SECREL
+
+# We explicitly add padding to put string outside of the 16bit address space
+# (absolute and as an offset from .data), so that relocations involving
+# 32bit addresses / offsets are not accidentally truncated to 16 bits.
+	.space 65536
+	.global string
+	.align 1
+string:
+	.asciz "Hello World!\n"




More information about the llvm-commits mailing list