Add --build-id=uuid support for MinGW32.
authorIgor Kudrin <ikudrin@accesssoftek.com>
Mon, 21 Nov 2016 17:59:37 +0000 (09:59 -0800)
committerCary Coutant <ccoutant@gmail.com>
Mon, 21 Nov 2016 17:59:37 +0000 (09:59 -0800)
2016-11-21  Igor Kudrin  <ikudrin@accesssoftek.com>

gold/
* layout.cc: Include windows.h and rpcdce.h (for MinGW32).
(Layout::create_build_id): Generate uuid using UuidCreate().

gold/ChangeLog
gold/layout.cc

index 0013288a9551b10739e4903237e57887a65287cd..bb035f38f85674c3910e6be7b243f47e5f14ec59 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-21  Igor Kudrin  <ikudrin@accesssoftek.com>
+
+       * layout.cc: Include windows.h and rpcdce.h (for MinGW32).
+       (Layout::create_build_id): Generate uuid using UuidCreate().
+
 2016-11-04  Loïc Yhuel <loic.yhuel@softathome.com>
 
        * configure.ac: add missing '$'.
index d14f27bddfcf48d1465e60cf0f6889c85ce5bb05..c9ea9ebed477d6315de6f6013f75f28d15dabdfa 100644 (file)
 #include "libiberty.h"
 #include "md5.h"
 #include "sha1.h"
+#ifdef __MINGW32__
+#include <windows.h>
+#include <rpcdce.h>
+#endif
 
 #include "parameters.h"
 #include "options.h"
@@ -3067,6 +3071,7 @@ Layout::create_build_id()
     descsz = 160 / 8;
   else if (strcmp(style, "uuid") == 0)
     {
+#ifndef __MINGW32__
       const size_t uuidsz = 128 / 8;
 
       char buffer[uuidsz];
@@ -3089,6 +3094,26 @@ Layout::create_build_id()
 
       desc.assign(buffer, uuidsz);
       descsz = uuidsz;
+#else // __MINGW32__
+      UUID uuid;
+      typedef RPC_STATUS (RPC_ENTRY *UuidCreateFn)(UUID *Uuid);
+
+      HMODULE rpc_library = LoadLibrary("rpcrt4.dll");
+      if (!rpc_library)
+       gold_error(_("--build-id=uuid failed: could not load rpcrt4.dll"));
+      else
+       {
+         UuidCreateFn uuid_create = reinterpret_cast<UuidCreateFn>(
+             GetProcAddress(rpc_library, "UuidCreate"));
+         if (!uuid_create)
+           gold_error(_("--build-id=uuid failed: could not find UuidCreate"));
+         else if (uuid_create(&uuid) != RPC_S_OK)
+           gold_error(_("__build_id=uuid failed: call UuidCreate() failed"));
+         FreeLibrary(rpc_library);
+       }
+      desc.assign(reinterpret_cast<const char *>(&uuid), sizeof(UUID));
+      descsz = sizeof(UUID);
+#endif // __MINGW32__
     }
   else if (strncmp(style, "0x", 2) == 0)
     {