diff options
author | Frederich Munch <colsebas@hotmail.com> | 2017-04-27 16:55:24 +0000 |
---|---|---|
committer | Frederich Munch <colsebas@hotmail.com> | 2017-04-27 16:55:24 +0000 |
commit | c1db8cf9c1ddf2a113312b81e467fcd5b6f30194 (patch) | |
tree | 8076ffd8cd6c278b852bcf077ec6b7ba74c4978b /llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx | |
parent | d21601a92917f5d353d3cb0e51b48e07f85ded8e (diff) | |
download | bcm5719-llvm-c1db8cf9c1ddf2a113312b81e467fcd5b6f30194.tar.gz bcm5719-llvm-c1db8cf9c1ddf2a113312b81e467fcd5b6f30194.zip |
Refactor DynamicLibrary so searching for a symbol will have a defined order and
libraries are properly unloaded when llvm_shutdown is called.
Summary:
This was mostly affecting usage of the JIT, where storing the library handles in
a set made iteration unordered/undefined. This lead to disagreement between the
JIT and native code as to what the address and implementation of particularly on
Windows with stdlib functions:
JIT: putenv_s("TEST", "VALUE") // called msvcrt.dll, putenv_s
JIT: getenv("TEST") -> "VALUE" // called msvcrt.dll, getenv
Native: getenv("TEST") -> NULL // called ucrt.dll, getenv
Also fixed is the issue of DynamicLibrary::getPermanentLibrary(0,0) on Windows
not giving priority to the process' symbols as it did on Unix.
Reviewers: chapuni, v.g.vassilev, lhames
Reviewed By: lhames
Subscribers: danalbert, srhines, mgorny, vsk, llvm-commits
Differential Revision: https://reviews.llvm.org/D30107
llvm-svn: 301562
Diffstat (limited to 'llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx')
-rw-r--r-- | llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx b/llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx new file mode 100644 index 00000000000..1de85236a88 --- /dev/null +++ b/llvm/unittests/Support/DynamicLibrary/PipSqueak.cxx @@ -0,0 +1,36 @@ +//===- llvm/unittest/Support/DynamicLibrary/PipSqueak.cxx -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "PipSqueak.h" +#include <string> + +struct Global { + std::string *Str; + Global() : Str(nullptr) {} + ~Global() { + if (Str) + *Str = "Global::~Global"; + } +}; + +struct Local { + std::string &Str; + Local(std::string &S) : Str(S) { Str = "Local::Local"; } + ~Local() { Str = "Local::~Local"; } +}; + +static Global Glb; + +extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr, + std::string &LStr) { + static Local Lcl(LStr); + Glb.Str = &GStr; +} + +extern "C" PIPSQUEAK_EXPORT const char *TestA() { return "LibCall"; } |