From e02b739124797465ef3e95a78eb3bdb1704ce17b Mon Sep 17 00:00:00 2001 From: coleenp Date: Tue, 1 Feb 2011 11:23:19 -0500 Subject: [PATCH] 6588413: Use -fvisibility=hidden for gcc compiles Summary: Add option for gcc 4 and above, define JNIEXPORT and JNIIMPORT to visibility=default, add for jio_snprintf and others since -fvisibility=hidden overrides --version-script definitions. Reviewed-by: kamg, never --- make/linux/makefiles/gcc.make | 5 ++ make/linux/makefiles/mapfile-vers-debug | 8 ---- make/linux/makefiles/mapfile-vers-product | 8 ---- src/cpu/sparc/vm/jni_sparc.h | 9 +++- src/cpu/x86/vm/jni_x86.h | 8 +++- src/cpu/zero/vm/jni_zero.h | 10 +++- src/os/linux/vm/jvm_linux.cpp | 5 -- src/os/linux/vm/os_linux.cpp | 46 ++----------------- src/os/solaris/vm/os_solaris.cpp | 4 +- src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp | 2 +- src/os_cpu/linux_x86/vm/os_linux_x86.cpp | 2 +- src/os_cpu/linux_zero/vm/os_linux_zero.cpp | 2 +- .../solaris_sparc/vm/os_solaris_sparc.cpp | 6 +-- src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp | 6 +-- src/share/vm/prims/forte.cpp | 1 + src/share/vm/prims/jvm.cpp | 2 +- src/share/vm/prims/jvm.h | 8 ++-- 17 files changed, 50 insertions(+), 82 deletions(-) diff --git a/make/linux/makefiles/gcc.make b/make/linux/makefiles/gcc.make index aa879b10f..04c407bce 100644 --- a/make/linux/makefiles/gcc.make +++ b/make/linux/makefiles/gcc.make @@ -75,6 +75,11 @@ CFLAGS += -fno-rtti CFLAGS += -fno-exceptions CFLAGS += -D_REENTRANT CFLAGS += -fcheck-new +# version 4 and above support fvisibility=hidden (matches jni_x86.h file) +# except 4.1.2 gives pointless warnings that can't be disabled (afaik) +ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" +CFLAGS += -fvisibility=hidden +endif ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) ARCHFLAG/i486 = -m32 -march=i586 diff --git a/make/linux/makefiles/mapfile-vers-debug b/make/linux/makefiles/mapfile-vers-debug index a7ba4583e..7022aba2e 100644 --- a/make/linux/makefiles/mapfile-vers-debug +++ b/make/linux/makefiles/mapfile-vers-debug @@ -262,14 +262,6 @@ SUNWprivate_1.1 { JVM_SetField; JVM_SetPrimitiveField; - # Needed for dropping VM into JDK 1.3.x, 1.4 - _JVM_native_threads; - jdk_sem_init; - jdk_sem_post; - jdk_sem_wait; - jdk_pthread_sigmask; - jdk_waitpid; - # debug JVM JVM_AccessVMBooleanFlag; JVM_AccessVMIntFlag; diff --git a/make/linux/makefiles/mapfile-vers-product b/make/linux/makefiles/mapfile-vers-product index 7f7e279aa..201252d2d 100644 --- a/make/linux/makefiles/mapfile-vers-product +++ b/make/linux/makefiles/mapfile-vers-product @@ -262,14 +262,6 @@ SUNWprivate_1.1 { JVM_SetField; JVM_SetPrimitiveField; - # Needed for dropping VM into JDK 1.3.x, 1.4 - _JVM_native_threads; - jdk_sem_init; - jdk_sem_post; - jdk_sem_wait; - jdk_pthread_sigmask; - jdk_waitpid; - # miscellaneous functions jio_fprintf; jio_printf; diff --git a/src/cpu/sparc/vm/jni_sparc.h b/src/cpu/sparc/vm/jni_sparc.h index 9712dfc9d..2e177a869 100644 --- a/src/cpu/sparc/vm/jni_sparc.h +++ b/src/cpu/sparc/vm/jni_sparc.h @@ -23,8 +23,13 @@ * questions. */ -#define JNIEXPORT -#define JNIIMPORT +#if defined(__GNUC__) && (__GNUC__ >= 4) + #define JNIEXPORT __attribute__((visibility("default"))) + #define JNIIMPORT __attribute__((visibility("default"))) +#else + #define JNIEXPORT + #define JNIIMPORT +#endif #define JNICALL typedef int jint; diff --git a/src/cpu/x86/vm/jni_x86.h b/src/cpu/x86/vm/jni_x86.h index c6d322f2b..9715d0e32 100644 --- a/src/cpu/x86/vm/jni_x86.h +++ b/src/cpu/x86/vm/jni_x86.h @@ -27,10 +27,16 @@ #define _JAVASOFT_JNI_MD_H_ #if defined(SOLARIS) || defined(LINUX) + +#if defined(__GNUC__) && (__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2) + #define JNIEXPORT __attribute__((visibility("default"))) + #define JNIIMPORT __attribute__((visibility("default"))) +#else #define JNIEXPORT #define JNIIMPORT - #define JNICALL +#endif + #define JNICALL typedef int jint; #ifdef _LP64 diff --git a/src/cpu/zero/vm/jni_zero.h b/src/cpu/zero/vm/jni_zero.h index 0e21634df..132a6bbb6 100644 --- a/src/cpu/zero/vm/jni_zero.h +++ b/src/cpu/zero/vm/jni_zero.h @@ -24,8 +24,14 @@ * questions. */ -#define JNIEXPORT -#define JNIIMPORT + +#if defined(__GNUC__) && (__GNUC__ >= 4) + #define JNIEXPORT __attribute__((visibility("default"))) + #define JNIIMPORT __attribute__((visibility("default"))) +#else + #define JNIEXPORT + #define JNIIMPORT +#endif #define JNICALL typedef int jint; diff --git a/src/os/linux/vm/jvm_linux.cpp b/src/os/linux/vm/jvm_linux.cpp index ea5bf2d36..6e305b802 100644 --- a/src/os/linux/vm/jvm_linux.cpp +++ b/src/os/linux/vm/jvm_linux.cpp @@ -29,11 +29,6 @@ #include -/* - * FIXME: This is temporary hack to keep Linux Runtime.exec() - * code happy. See $JDK/src/linux/native/java/lang/UnixProcess_md.c - */ -int _JVM_native_threads = 1; // sun.misc.Signal /////////////////////////////////////////////////////////// // Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23 diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index 5d34fc50c..8f9c60cfd 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -2509,8 +2509,10 @@ char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info return end; } -extern "C" void numa_warn(int number, char *where, ...) { } -extern "C" void numa_error(char *where) { } +// Something to do with the numa-aware allocator needs these symbols +extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { } +extern "C" JNIEXPORT void numa_error(char *where) { } +extern "C" JNIEXPORT int fork1() { return fork(); } // If we are running with libnuma version > 2, then we should @@ -3483,7 +3485,7 @@ bool os::is_interrupted(Thread* thread, bool clear_interrupted) { // Note that the VM will print warnings if it detects conflicting signal // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". // -extern "C" int +extern "C" JNIEXPORT int JVM_handle_linux_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized); @@ -4678,44 +4680,6 @@ void os::pause() { } } -extern "C" { - -/** - * NOTE: the following code is to keep the green threads code - * in the libjava.so happy. Once the green threads is removed, - * these code will no longer be needed. - */ -int -jdk_waitpid(pid_t pid, int* status, int options) { - return waitpid(pid, status, options); -} - -int -fork1() { - return fork(); -} - -int -jdk_sem_init(sem_t *sem, int pshared, unsigned int value) { - return sem_init(sem, pshared, value); -} - -int -jdk_sem_post(sem_t *sem) { - return sem_post(sem); -} - -int -jdk_sem_wait(sem_t *sem) { - return sem_wait(sem); -} - -int -jdk_pthread_sigmask(int how , const sigset_t* newmask, sigset_t* oldmask) { - return pthread_sigmask(how , newmask, oldmask); -} - -} // Refer to the comments in os_solaris.cpp park-unpark. // diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp index 80c7c4d50..fad8d4466 100644 --- a/src/os/solaris/vm/os_solaris.cpp +++ b/src/os/solaris/vm/os_solaris.cpp @@ -4221,7 +4221,9 @@ void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* met // Note that the VM will print warnings if it detects conflicting signal // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". // -extern "C" int JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized); +extern "C" JNIEXPORT int +JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, + int abort_if_unrecognized); void signalHandler(int sig, siginfo_t* info, void* ucVoid) { diff --git a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp index e759e7d8d..a9984d0e6 100644 --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp @@ -542,7 +542,7 @@ inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { return false; } -extern "C" int +extern "C" JNIEXPORT int JVM_handle_linux_signal(int sig, siginfo_t* info, void* ucVoid, diff --git a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp index f657dfec2..b5e159076 100644 --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp @@ -216,7 +216,7 @@ extern "C" void FetchNPFI () ; extern "C" void FetchNResume () ; #endif // AMD64 -extern "C" int +extern "C" JNIEXPORT int JVM_handle_linux_signal(int sig, siginfo_t* info, void* ucVoid, diff --git a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp index 40e15e2f4..afeb60a93 100644 --- a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp +++ b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp @@ -116,7 +116,7 @@ frame os::fetch_frame_from_context(void* ucVoid) { ShouldNotCallThis(); } -extern "C" int +extern "C" JNIEXPORT int JVM_handle_linux_signal(int sig, siginfo_t* info, void* ucVoid, diff --git a/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp b/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp index 3b83be3eb..e9724f1cd 100644 --- a/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp +++ b/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp @@ -317,9 +317,9 @@ extern "C" void Fetch32Resume () ; extern "C" void FetchNPFI () ; extern "C" void FetchNResume () ; -extern "C" int JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized); - -int JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { +extern "C" JNIEXPORT int +JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid, + int abort_if_unrecognized) { ucontext_t* uc = (ucontext_t*) ucVoid; Thread* t = ThreadLocalStorage::get_thread_slow(); diff --git a/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp b/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp index d9bb0eb58..2de4d6969 100644 --- a/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp +++ b/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp @@ -365,8 +365,6 @@ bool os::is_allocatable(size_t bytes) { } -extern "C" int JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized); - extern "C" void Fetch32PFI () ; extern "C" void Fetch32Resume () ; #ifdef AMD64 @@ -374,7 +372,9 @@ extern "C" void FetchNPFI () ; extern "C" void FetchNResume () ; #endif // AMD64 -int JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { +extern "C" JNIEXPORT int +JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid, + int abort_if_unrecognized) { ucontext_t* uc = (ucontext_t*) ucVoid; #ifndef AMD64 diff --git a/src/share/vm/prims/forte.cpp b/src/share/vm/prims/forte.cpp index c1cb55312..3c48f01d2 100644 --- a/src/share/vm/prims/forte.cpp +++ b/src/share/vm/prims/forte.cpp @@ -520,6 +520,7 @@ static void forte_fill_call_trace_given_top(JavaThread* thd, // method_id - jmethodID of the method being executed extern "C" { +JNIEXPORT void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) { // This is if'd out because we no longer use thread suspension. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp index 86851e686..417052502 100644 --- a/src/share/vm/prims/jvm.cpp +++ b/src/share/vm/prims/jvm.cpp @@ -2585,7 +2585,7 @@ int jio_vfprintf(FILE* f, const char *fmt, va_list args) { } -int jio_printf(const char *fmt, ...) { +JNIEXPORT int jio_printf(const char *fmt, ...) { int len; va_list args; va_start(args, fmt); diff --git a/src/share/vm/prims/jvm.h b/src/share/vm/prims/jvm.h index ec8ca4049..07097af3c 100644 --- a/src/share/vm/prims/jvm.h +++ b/src/share/vm/prims/jvm.h @@ -1417,16 +1417,16 @@ JVM_GetHostName(char* name, int namelen); * BE CAREFUL! The following functions do not implement the * full feature set of standard C printf formats. */ -int +JNIEXPORT int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args); -int +JNIEXPORT int jio_snprintf(char *str, size_t count, const char *fmt, ...); -int +JNIEXPORT int jio_fprintf(FILE *, const char *fmt, ...); -int +JNIEXPORT int jio_vfprintf(FILE *, const char *fmt, va_list args); -- GitLab