프로그래밍 언어/C/C++

GCC 옵션 : version script

소혼 2012. 8. 14. 08:02
반응형
참고 : http://korea.gnu.org/manual/release/ld/ld-sjp/ld-ko_2.html
참고2: http://studyfoss.egloos.com/5254916
참고3: http://stackoverflow.com/questions/8129782/version-script-and-hidden-visibility

gcc 옵션 중 version script라는 게 있다는 사실을 알았다.

정확히는 ld 옵션이기 때문에 gcc에서 옵션을 줄 때는

-Wl,--version-script=파일 경로

의 형태를 가져야 한다.

참고2에서는 버전 관리를 위해 사용했으나,
버전 관리 뿐 아니라 심볼 개수를 줄이는 용도로도 활용이 가능한가 보다.

예컨데,

// 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

visibility가 default인 값은 두개지만, 그중 exported만 보이는 것을 알 수 있다.

반응형