Re: usage of --start-group and --end-group

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17 May 2018 at 09:34, tong chen wrote:
> Thanks for your reply, but is this true?

Yes.

> There is some text from <Using ld, the GNU Linker> book:
>
> The specified archives are searched repeatedly until no new undefined 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 symbol referred to by an object in an archive that appears later
> on the command line, the linker would not be able to resolve that reference.
> By grouping the archives, they all be searched repeatedly until all possible
> references are resolved.
>
> According to this, is the grouped archives will be searched repeatedly while
> processing every archives on the command line, even they appears later??

No. They will be searched repeatedly "until no new undefined
references are created". If they appear early in the command then
there are no undefined references, so the linker stops searching in
the group. If later objects create new undefined references the linker
does not go back to groups that have already been processed.

You can test this very easily for yourself:

$ echo "void a() { }" > a.c
$ echo "void b() { }" > b.c
$ gcc -c a.c b.c
$ ar cr liba.a a.o
$ ar cr libb.a b.o
$ echo "void a(void); void b(void); int main() { a(); b(); }" > main.c
$ gcc -Wl,--start-group,liba.a,libb.a,--end-group main.c
/tmp/ccUxsewX.o: In function `main':
main.c:(.text+0x5): undefined reference to `a'
main.c:(.text+0xa): undefined reference to `b'
collect2: error: ld returned 1 exit status
$ gcc main.c -Wl,--start-group,liba.a,libb.a,--end-group
$

--start-group and --end-group do not completely remove the need to get
the order correct.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux