[PATCH] MCWin64EH: reloctions must be IMGREL32

Kai Nacke kai.nacke at redstar.de
Tue May 14 12:14:33 PDT 2013


Hi!

In order to generate the right data and keep the MS linker happy the 
relocations in the Win64 EH data structures must be of type 
IMAGE_REL_AMD64_ADDR32NB instead of IMAGE_REL_AMD64_ADDR32. This is 
easiely achieved by adding the VK_COFF_IMGREL32 modifier to the symbol 
reference.

Please review.

Regards
Kai
-------------- next part --------------
diff --git a/lib/MC/MCWin64EH.cpp b/lib/MC/MCWin64EH.cpp
index c5b637c..c66c6d9 100644
--- a/lib/MC/MCWin64EH.cpp
+++ b/lib/MC/MCWin64EH.cpp
@@ -134,9 +134,15 @@ static void EmitRuntimeFunction(MCStreamer &streamer,
   MCContext &context = streamer.getContext();
 
   streamer.EmitValueToAlignment(4);
-  streamer.EmitValue(MCSymbolRefExpr::Create(info->Begin, context), 4);
-  streamer.EmitValue(MCSymbolRefExpr::Create(info->End, context), 4);
-  streamer.EmitValue(MCSymbolRefExpr::Create(info->Symbol, context), 4);
+  streamer.EmitValue(MCSymbolRefExpr::Create(info->Begin,
+                                             MCSymbolRefExpr::VK_COFF_IMGREL32,
+                                             context), 4);
+  streamer.EmitValue(MCSymbolRefExpr::Create(info->End,
+                                             MCSymbolRefExpr::VK_COFF_IMGREL32,
+                                             context), 4);
+  streamer.EmitValue(MCSymbolRefExpr::Create(info->Symbol,
+                                             MCSymbolRefExpr::VK_COFF_IMGREL32,
+                                             context), 4);
 }
 
 static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info) {
@@ -189,8 +195,9 @@ static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info) {
     EmitRuntimeFunction(streamer, info->ChainedParent);
   else if (flags &
            ((Win64EH::UNW_TerminateHandler|Win64EH::UNW_ExceptionHandler) << 3))
-    streamer.EmitValue(MCSymbolRefExpr::Create(info->ExceptionHandler, context),
-                       4);
+    streamer.EmitValue(MCSymbolRefExpr::Create(info->ExceptionHandler,
+                                              MCSymbolRefExpr::VK_COFF_IMGREL32,
+                                              context), 4);
   else if (numCodes < 2) {
     // The minimum size of an UNWIND_INFO struct is 8 bytes. If we're not
     // a chained unwind info, if there is no handler, and if there are fewer


More information about the llvm-commits mailing list