[compiler-rt] r182276 - [nolibc] Make GetArgsAndEnv libc-independent.
Peter Collingbourne
peter at pcc.me.uk
Mon May 20 07:25:32 PDT 2013
Author: pcc
Date: Mon May 20 09:25:32 2013
New Revision: 182276
URL: http://llvm.org/viewvc/llvm-project?rev=182276&view=rev
Log:
[nolibc] Make GetArgsAndEnv libc-independent.
__libc_stack_end is made into a weak symbol if possible. If libc is
not linked, read args and environment from /proc.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=182276&r1=182275&r2=182276&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Mon May 20 09:25:32 2013
@@ -315,21 +315,11 @@ bool SetEnv(const char *name, const char
}
#endif
-#ifdef __GLIBC__
-
extern "C" {
- extern void *__libc_stack_end;
-}
-
-static void GetArgsAndEnv(char ***argv, char ***envp) {
- uptr *stack_end = (uptr *)__libc_stack_end;
- int argc = *stack_end;
- *argv = (char**)(stack_end + 1);
- *envp = (char**)(stack_end + argc + 2);
+ extern void *__libc_stack_end SANITIZER_WEAK_ATTRIBUTE;
}
-#else // __GLIBC__
-
+#if !SANITIZER_GO
static void ReadNullSepFileToArray(const char *path, char ***arr,
int arr_size) {
char *buff;
@@ -348,15 +338,25 @@ static void ReadNullSepFileToArray(const
}
(*arr)[count] = 0;
}
+#endif
-static void GetArgsAndEnv(char ***argv, char ***envp) {
- static const int kMaxArgv = 2000, kMaxEnvp = 2000;
- ReadNullSepFileToArray("/proc/self/cmdline", argv, kMaxArgv);
- ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);
+static void GetArgsAndEnv(char*** argv, char*** envp) {
+#if !SANITIZER_GO
+ if (&__libc_stack_end) {
+#endif
+ uptr* stack_end = (uptr*)__libc_stack_end;
+ int argc = *stack_end;
+ *argv = (char**)(stack_end + 1);
+ *envp = (char**)(stack_end + argc + 2);
+#if !SANITIZER_GO
+ } else {
+ static const int kMaxArgv = 2000, kMaxEnvp = 2000;
+ ReadNullSepFileToArray("/proc/self/cmdline", argv, kMaxArgv);
+ ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);
+ }
+#endif
}
-#endif // __GLIBC__
-
void ReExec() {
char **argv, **envp;
GetArgsAndEnv(&argv, &envp);
More information about the llvm-commits
mailing list