[cmake-developers] GCC link options

J Decker d3ck0r at gmail.com
Tue Jul 24 12:58:08 EDT 2012


Okay I think maybe it's that the marker for the end of the list is not
in the right spot.
All my other projects I have been building as shared libraries, but
this one is based on static libs.

I need to specify at the end of all libraries a seperate library....
but after all the libraries that have been applied to this exectuable
target are a bunch more libraries, presumably the ones that are
recursively referenced by other libs....

So how can I add a library to the very end of the list to link?

On Mon, Jul 23, 2012 at 5:35 PM, J Decker <d3ck0r at gmail.com> wrote:
> On Mon, Jul 23, 2012 at 2:45 PM, Brad King <brad.king at kitware.com> wrote:
>> On 07/23/2012 02:31 PM, J Decker wrote:
>>> In this commit --no-whole-archive is artificially added to compile
>>> options in Modules/Platform/Windows-GNU.cmake.
>>>
>>> http://cmake.org/gitweb?p=cmake.git;a=commit;h=5f05a3c25e1480648f46c9ccbf775225f9e8e32d
>>>
>>> This is causes no end of problems for me; because I have code which is
>>> indirectly referenced such that LD doesn't identify it as being used.
>>
>> By what mechanism is code "indirectly referenced" such that
>> references are not visible to the linker?
>>
>
> I'm not entirely sure...  these are the defines/relavent data structures...
>
> even though I apply  __attribute__((used)), though it's in another
> section __attribute__((section("deadstart_list"))) ...
>
> so the static routine and the static structure should be kept; part of
> the init of the structure is the address of the routine to make sure
> that's kept... but the only references are between the data and the
> code... but somehow these blocks of code and data are being omitted
> when linking from .a files.
>
> I link a object at the start and end that contain the beginning and
> end of 'deadstart_list' section, which I go through and use all the
> structures that have been compiled there.  It's a way to schedule
> pre-runtime code initializers... (things that run before main)
>
> typedef unsigned char   __type_rtp;
> typedef void(*__type_rtn ) ( void );
> struct rt_init // structure placed in XI/YI segment
> {
> #ifdef __cplusplus
>         //rt_init( int _rtn_type ) { rt_init::rtn_type = _rtn_type; }
>         /*rt_init( int _priority, CTEXTSTR name, __type_rtn rtn, CTEXTSTR
> _file, int _line )
>         {
>                 rtn_type = 0;
>                 scheduled = 0;
>                 priority = priority;
>                 file = _file;
>                 line = _line;
>       routine = rtn;
>                 }
>       */
> #endif
> #define DEADSTART_RT_LIST_START 0xFF
>     __type_rtp  rtn_type; // - near=0/far=1 routine indication
>                           //   also used when walking table to flag
>                           //   completed entries
>     __type_rtp  scheduled; // has this been scheduled? (0 if no)
>     __type_rtp  priority; // - priority (0-highest 255-lowest)
> #define INIT_PADDING ,{0}
>          char padding[1]; // need this otherwise it's 23 bytes and that'll be bad.
>          int line; // 32 bits in 64 bits....
>          __type_rtn  routine;      // - routine (rtn)
>          CTEXTSTR file;
>          CTEXTSTR funcname;
>          struct rt_init *junk;
> .        struct rt_init *junk2[3];
> . __attribute__((packed));
>
> #define JUNKINIT(name) ,&pastejunk(name,_ctor_label)
> #define RTINIT_STATIC static
>
> #define PRIORITY_PRELOAD(name,pr) static void name(void); \
>         RTINIT_STATIC struct rt_init pastejunk(name,_ctor_label) \
>           __attribute__((section("deadstart_list"))) __attribute__((used)) \
>         ={0,0,pr INIT_PADDING    \
>          ,__LINE__,name         \
>          ,WIDE__FILE__        \
>         ,#name        \
>         JUNKINIT(name)}; \
>         static void name(void) __attribute__((used));  \
>         void name(void)
>
>
>
>> Depending on your use case consider the object library feature:
>>
>>  http://www.cmake.org/Wiki/CMake/Tutorials/Object_Library
>>
>>> any idea how I can get around the --no-whole-archive flag?
>>
>> target_link_libraries(my_target -Wl,--whole-archive my_archive)
>
> I'll try adding that as the first library...
>
>>
>> -Brad



More information about the cmake-developers mailing list