[LLVMbugs] [Bug 20076] New: clang-cl generates incorrect code for globals without static initializers which have references to imported functions
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jun 18 07:21:01 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20076
Bug ID: 20076
Summary: clang-cl generates incorrect code for globals without
static initializers which have references to imported
functions
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: ehsan at mozilla.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
We hit this bug during the startup of Firefox built with clang-cl. Here is a
reduced test case. It consists of a DLL and an executable, and the bug only
hits the codegen in the executable (test.cc). See below for the full test case
including building instructions. We tested this against MSVC 2012.
Also note that if you force mi below to get a static initializer (for example
by initializing the second member to rand() instead of 5), the bug goes away.
This happens because clang-cl generates code to read the value of foo out of
the IAT in this scenario.
$ cat test.cc
extern __declspec(dllimport) void test_output(struct ehsan*);
extern __declspec(dllimport) int foo(const char *);
struct ehsan {
int (*f)(const char *);
int k;
};
ehsan mi = { foo, 5 };
int main(int argc, const char **argv)
{
test_output(&mi);
return 0;
}
$ cat foo.cc
#include <stdio.h>
__declspec(dllexport) int foo(const char*s)
{
return 5;
}
struct ehsan {
int (*f)(const char *);
int k;
};
__declspec(dllexport) void test_output(struct ehsan *s)
{
printf("%p %p\n", foo, s->f);
}
$ cl foo.cc -link -dll -out:foo.dll
$ clang-cl test.cc foo.lib
$ ./test.exe
621F1000 008F1032
$ cl test.cc foo.lib
$ ./test.exe
621F1000 621F1000
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140618/4de04e12/attachment.html>
More information about the llvm-bugs
mailing list