3 Replies Latest reply on May 29, 2009 3:58 PM by 807578

    Sun Studio cc includes unused static inline functions in object file

    807578
      While trying to compile some code originally compiled with GCC I run into a linking problem. My problem seems to be caused by that GCC does not include unused static inline functions in the object files while cc does. The following simple example can be used for illustrating this:
      void foo();
      
      static inline void bar()
      {
        foo();
      }
      
      int main()
      {
      
      }
      This program compiles and links without any problems using GCC and Sun Studio 12 CC (the C++ compiler) but fails to link using Sun Studio 12 cc:

      khepri%> cc staticinline.c
      Undefined first referenced
      symbol in file
      foo staticinline.o
      ld: fatal: Symbol referencing errors. No output written to a.out

      It is probably fine of cc to include foo() in the object file (although not necessary?). My questions are:

      1. Are there any reasons for why cc includes unused static inline functions in the object file while CC does not?
      2. Are there any ways or options to tell cc to not include unused static inline functions in the object file?

      In the example above this is easy to fix by just removing or #ifdef away the code but the original code where I have this problem is not maintained by me and the static inline functions are in header files that get included in multiple C files and in some of these the functions are used.

      Thanks,
      Olav