Move environ valiable into it's own file
Test: build statically the example program below
char** environ;
int main() {
}
Change-Id: I3f01652da1d5063d92ba7cbff7fb09bd0a89325c
diff --git a/libc/Android.bp b/libc/Android.bp
index 4f6ff1a..cd2a727 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1357,6 +1357,7 @@
"bionic/ctype.cpp",
"bionic/dirent.cpp",
"bionic/dup2.cpp",
+ "bionic/environ.cpp",
"bionic/epoll_create.cpp",
"bionic/epoll_pwait.cpp",
"bionic/epoll_wait.cpp",
diff --git a/libc/bionic/environ.cpp b/libc/bionic/environ.cpp
new file mode 100644
index 0000000..363c1fd
--- /dev/null
+++ b/libc/bionic/environ.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+// Keep that variable in separate .o file to make sure programs which define
+// their own "environ" are compileable.
+char** environ;
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index e051762..48fd670 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -59,9 +59,6 @@
// Not public, but well-known in the BSDs.
const char* __progname;
-// Declared in <unistd.h>.
-char** environ;
-
#if defined(__i386__)
__attribute__((__naked__)) static void __libc_int0x80() {
__asm__ volatile("int $0x80; ret");