Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp
diff --git a/third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp b/third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0f43eaa11c0b0a3668e13ee5454cccbcbcb67e35
--- /dev/null
+++ b/third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp
@@ -0,0 +1,48 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This source file must contain a static destructor to check that
+// the crazy linker can resolve weak symbols from the C library,
+// like __aeabi_atexit(), which are not normally returned by
+// a call to dlsym().
+
+// Libc is not required to copy strings passed to putenv(). If it does
+// not then env pointers become invalid when rodata is unmapped on
+// library unload. To guard against this, putenv() strings are first
+// strdup()'ed. This is a mild memory leak.
+
+#include <stdlib.h>
+
+#ifdef __arm__
+extern "C" void __aeabi_atexit(void*);
+#endif
+
+class A {
+ public:
+ A() {
+ x_ = rand();
+ const char* env = getenv("TEST_VAR");
+ if (!env || strcmp(env, "INIT"))
+ putenv(strdup("TEST_VAR=LOAD_ERROR"));
+ else
+ putenv(strdup("TEST_VAR=LOADED"));
+ }
+
+ ~A() {
+ const char* env = getenv("TEST_VAR");
+ if (!env || strcmp(env, "LOADED"))
+ putenv(strdup("TEST_VAR=UNLOAD_ERROR"));
+ else
+ putenv(strdup("TEST_VAR=UNLOADED"));
+ }
+
+ int Get() const { return x_; }
+
+ private:
+ int x_;
+};
+
+A s_a;
+
+extern "C" int Foo() { return s_a.Get(); }
« no previous file with comments | « third_party/android_crazy_linker/src/tests/foo_with_relro.cpp ('k') | third_party/android_crazy_linker/src/tests/jni_lib.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698