The difference in behavior between ld and gold when processing "start group/end group" option

Nikola Ikonic Nikola.Ikonic@rt-rk.com
Tue Mar 3 17:19:00 GMT 2015


Hello,

I have found a difference in behavior of gold and GNU ld when processing command line in one specific case when "start group/end group" is used in conjuction with linker script, and I am wondering if this difference is intentional or possible bug in either of linkers. In the example I have made, two libraries (libtest.a/libtest2.a) have different definitions of the same function and the command line uses linker script with a library name inside "start group/end group" option. Linker script only includes other libraries. When the same line is given to gold and GNU LD they call function from different libraries.

EXAMPLE:
main.c
extern void head_dummy();

int main(){
  head_dummy();
  return 0;
}

test.c
#include <stdio.h>

void dummy_func()
{
  printf("\nthis is library TEST\n\n");
}

test2.c
#include <stdio.h>

void dummy_func()
{
  printf("\nthis is library TEST2\n\n");
}

head_dummy.c
extern void dummy_func();    

void head_dummy()
{
  dummy_func();
}

libscript.a
GROUP ( libtest2.a libdummy.a )


$ gcc main.o -o main.exe -Wl,--start-group -Wl,-lscript -Wl,-ltest  -Wl,--end-group -L./

Executable linked with LD prints "... TEST2" while gold-linked executable prints "... TEST".

Which of these linkers behave correctly?

Thank you in advance for the explanation.



More information about the Binutils mailing list