version-script and hidden visibility

点点圈 提交于 2019-12-01 03:30:43

Your question makes no sense: why fight -fvisibility with a linker script, when you can use the linker script to export exactly what you need, and hide everything else:

{
  global: foobar;
  local: *;
};

Update:

Because the code I need to use this on uses __attribute__((visibility("default"))) ...

The linker script works just fine with symbols so marked. Example:

// t.c
int __attribute__((visibility("default"))) foo() { return 1; }
int bar() { return 2; }
int __attribute__((visibility("default"))) exported() { return 3; }

// t.lds
{
  global: exported;
  local: *;
};

gcc t.c -Wl,--version-script=t.lds -fPIC -shared -o t.so && nm -D t.so
                 w _Jv_RegisterClasses
                 w __cxa_finalize
                 w __gmon_start__
00000000000004f2 T exported
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!