ld 命令行选项 & ld_static

ld
       –start-group archives –end-group
           The archives should be a list of archive files. They may be either
           explicit file names, or -l options.

           The specified archives are searched repeatedly until no new unde-
           fined references are created. Normally, an archive is searched
           only once in the order that it is specified on the command line.
           If a symbol in that archive is needed to resolve an undefined sym-
           bol referred to by an object in an archive that appears later on
           the command line, the linker would not be able to resolve that ref-
           erence.   By grouping the archives, they all be searched repeatedly
           until all possible references are resolved.

           Using this option has a significant performance cost. It is best
           to use it only when there are unavoidable circular references
           between two or more archives.

       -M
       –print-map
           Print a link map to the standard output. A link map provides
           information about the link, including the following:

           - Where object files and symbols are mapped into memory.

           - How common symbols are allocated.

           - All archive members included in the link, with a mention of the
               symbol which caused the archive member to be brought in.

       –dynamic-linker file
           Set the name of the dynamic linker. This is only meaningful when
           generating dynamically linked ELF executables. The default dynamic
           linker is normally correct; don’t use this unless you know what you
           are doing.

        –wrap symbol
Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "wrap_ symbol ". Any undefined reference to "real symbol " will be resolved to symbol.

This can be used to provide a wrapper for a system function. The wrapper function should be called "__wrap symbol ". If it wishes to call the system function, it should call "real_ symbol ".

Here is a trivial example:

void *
wrap_malloc (size_t c)
{
printf ("malloc called with %zun", c);
return real_malloc (c);
}

If you link other code with this file using –wrap malloc, then all calls to "malloc" will call the function "

wrap_malloc" instead. The call to "real_malloc" in "wrap_malloc" will call the real "malloc" function.

You may wish to provide a "real_malloc" function as well, so that links without the –wrap option will succeed. If you do this, you should not put the definition of "real_malloc" in the same file as "__wrap_malloc"; if you do, the assembler may resolve the call before the linker has a chance to wrap it to "malloc".

       -u symbol
       –undefined=symbol
           Force symbol to be entered in the output file as an undefined symbol. Doing this may, for example,
           trigger linking of additional modules from standard libraries. -u may be repeated with different
           option arguments to enter additional undefined symbols. This option is equivalent to the "EXTERN"
           linker script command.




===================================================================================================

ld_static

        -d, -dc, -dp                Force common symbols to be defined
        -r, -i, –relocatable       Generate relocatable output


eg:
ld_static -d -r -o /lib/modules/2.6.24-16-generic/volatile/fglrx.ko /lib/linux-restricted-modules/2.6.24-16-generic/fglrx/*









end