From bac8a5d2822835cf47175d1162030653fadd5c09 Mon Sep 17 00:00:00 2001
From: johannst tmp
program linked against lpthread
will
depend on the symbol version GLIBC_2.3.2
, which is the default version.
> echo "#include <pthread.h>
+> echo "#include <pthread.h>
int main() {
return pthread_cond_wait(0,0);
- }" | gcc -o tmp -xc - -lpthread;
+ }" | gcc -o tmp -xc - -lpthread;
readelf -W --dyn-syms tmp | grep pthread_cond_wait;
Symbol table '.dynsym' contains 7 entries:
@@ -272,23 +272,23 @@ symbol multiple times but in different versions.
// ..@ -> Is the unversioned symbol.
// ..@@.. -> Is the default symbol.
-__asm__(".symver func_v0,func@");
-__asm__(".symver func_v1,func@LIB_V1");
-__asm__(".symver func_v2,func@@LIB_V2");
+__asm__(".symver func_v0,func@");
+__asm__(".symver func_v1,func@LIB_V1");
+__asm__(".symver func_v2,func@@LIB_V2");
-extern "C" {
- void func_v0() { puts("func_v0"); }
- void func_v1() { puts("func_v1"); }
- void func_v2() { puts("func_v2"); }
+extern "C" {
+ void func_v0() { puts("func_v0"); }
+ void func_v1() { puts("func_v1"); }
+ void func_v2() { puts("func_v2"); }
}
-__asm__(".symver _Z11func_cpp_v1i,_Z8func_cppi@LIB_V1");
-__asm__(".symver _Z11func_cpp_v2i,_Z8func_cppi@@LIB_V2");
+__asm__(".symver _Z11func_cpp_v1i,_Z8func_cppi@LIB_V1");
+__asm__(".symver _Z11func_cpp_v2i,_Z8func_cppi@@LIB_V2");
-void func_cpp_v1(int) { puts("func_cpp_v1"); }
-void func_cpp_v2(int) { puts("func_cpp_v2"); }
+void func_cpp_v1(int) { puts("func_cpp_v1"); }
+void func_cpp_v2(int) { puts("func_cpp_v2"); }
-void func_cpp(int) { puts("func_cpp_v2"); }
+void func_cpp(int) { puts("func_cpp_v2"); }
Version script for libfoo
which defines which symbols for which versions are
exported from the ELF file.
@@ -296,8 +296,8 @@ exported from the ELF file.
LIB_V1 {
global:
func;
- extern "C++" {
- "func_cpp(int)";
+ extern "C++" {
+ "func_cpp(int)";
};
local:
*;
@@ -306,8 +306,8 @@ LIB_V1 {
LIB_V2 {
global:
func;
- extern "C++" {
- "func_cpp(int)";
+ extern "C++" {
+ "func_cpp(int)";
};
} LIB_V1;
@@ -339,7 +339,7 @@ Symbol table '.dynsym' contains 14 entries:
#include <assert.h>
// Links against default symbol in the lib.so.
-extern "C" void func();
+extern "C" void func();
int main() {
// Call the default version.
@@ -349,10 +349,10 @@ int main() {
typedef void (*fnptr)();
// Unversioned lookup.
- fnptr fn_v0 = (fnptr)dlsym(RTLD_DEFAULT, "func");
+ fnptr fn_v0 = (fnptr)dlsym(RTLD_DEFAULT, "func");
// Version lookup.
- fnptr fn_v1 = (fnptr)dlvsym(RTLD_DEFAULT, "func", "LIB_V1");
- fnptr fn_v2 = (fnptr)dlvsym(RTLD_DEFAULT, "func", "LIB_V2");
+ fnptr fn_v1 = (fnptr)dlvsym(RTLD_DEFAULT, "func", "LIB_V1");
+ fnptr fn_v2 = (fnptr)dlvsym(RTLD_DEFAULT, "func", "LIB_V2");
assert(fn_v0 != 0);
assert(fn_v1 != 0);
--
cgit v1.2.3