gcc - Cause link to fail if certain symbol is referenced -
is there way make linking fail if code references symbol library?
i seem remember dimly there such directive in linker script language, apparently not gnu ld (maybe it's false memory).
i need prevent part of third-party library accidentally linking application. if link, adds static initializers wreak havoc @ runtime (it's embedded project environment bit quirky). cannot change third-party library in question. detect error @ build time. guess can write post-build script parses map file , issues error if finds offending parts, mentioned above [false?] memory prompts me ascertain can't done using linker alone.
i'm using gnu gcc toolchain.
okay, stepping out lunch helped me find (pretty obvious) solution:
/* stubs.c */ void error_do_not_reference_this_symbol( void ); void offending3rdpartyfunction( void ) { error_do_not_reference_this_symbol(); }
here, symbol error_do_not_reference_this_symbol
never defined. additional source file added project, stubs 1 shown above each function must not referenced. if code reference 1 of these functions, stub take precedence on library-provided symbol, , link fail:
test.cpp:(.text._testfunc+0x4): undefined reference `error_do_not_reference_this_symbol()' collect2.exe: error: ld returned 1 exit status
Comments
Post a Comment