public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* G++ driver missing option when sending to collect2
@ 2021-02-25  2:13 Yeting Kuo
  2021-02-25  7:23 ` Jonathan Wakely
  2021-02-26 19:15 ` Jim Wilson
  0 siblings, 2 replies; 5+ messages in thread
From: Yeting Kuo @ 2021-02-25  2:13 UTC (permalink / raw)
  To: gcc-help

Hi all,
I have a compiler driver issue when using g++. I want to check whether it
is a bug.
I send '-Wl,--start-group x.o -lc -Wl,--end-group' to g++, but the command
collect2 received is '--start-group x.o --end-group' like the following
commands:

$ riscv32-unknown-elf-g++ test.o -Wl,--start-group x.o -lc -Wl,--end-group
-v 2>&1 | grep collect2
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/11.0.0/collect2
-plugin
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/11.0.0/liblto_plugin.so
-plugin-opt=/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/11.0.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccoy0c2c.res -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgloss
-plugin-opt=-pass-through=-lgcc -melf32lriscv
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/../../../../riscv32-unknown-elf/lib/crt0.o
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/crtbegin.o
-L/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0
-L/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc
-L/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/../../../../riscv32-unknown-elf/lib
test.o --start-group x.o --end-group -lstdc++ -lm -lc -lgcc --start-group
-lc -lgloss --end-group -lgcc
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/crtend.o

Also I don't have the issue when using gcc:
$riscv32-unknown-elf-gcc test.o -Wl,--start-group x.o -lc -Wl,--end-group
-v 2>&1 | grep collect2
 /home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/11.0.0/collect2
-plugin
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/11.0.0/liblto_plugin.so
-plugin-opt=/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/11.0.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/cccekJC0.res -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgloss
-plugin-opt=-pass-through=-lgcc -melf32lriscv
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/../../../../riscv32-unknown-elf/lib/crt0.o
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/crtbegin.o
-L/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0
-L/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc
-L/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/../../../../riscv32-unknown-elf/lib
test.o --start-group x.o -lc --end-group -lgcc --start-group -lc -lgloss
--end-group -lgcc
/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../lib/gcc/riscv32-unknown-elf/11.0.0/crtend.o

My g++ configuration:
$riscv32-unknown-elf-g++ -v
Using built-in specs.
COLLECT_GCC=/home/users1/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/riscv32-unknown-elf-g++
COLLECT_LTO_WRAPPER=/home/users/eddiekuo/upstream_toolchain/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/11.0.0/lto-wrapper
Target: riscv32-unknown-elf
Configured with: ../gcc/configure --target=riscv32-unknown-elf
--prefix=/home/users1/eddiekuo/upstream_toolchain/riscv32-unknown-elf
--enable-languages=c,c++ --disable-multilib --without-headers
--disable-shared --disable-threads --disable-libatomic --disable-libmudflap
--disable-libssp --with-newlib
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20210223 (experimental) (GCC)

Thanks,
Yeting

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: G++ driver missing option when sending to collect2
  2021-02-25  2:13 G++ driver missing option when sending to collect2 Yeting Kuo
@ 2021-02-25  7:23 ` Jonathan Wakely
  2021-02-26  1:57   ` Yeting Kuo
  2021-02-26 19:15 ` Jim Wilson
  1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2021-02-25  7:23 UTC (permalink / raw)
  To: Yeting Kuo; +Cc: gcc-help

On Thu, 25 Feb 2021, 02:46 Yeting Kuo via Gcc-help, <gcc-help@gcc.gnu.org>
wrote:

> Hi all,
> I have a compiler driver issue when using g++. I want to check whether it
> is a bug.
> I send '-Wl,--start-group x.o -lc -Wl,--end-group' to g++, but the command
> collect2 received is '--start-group x.o --end-group' like the following
> commands:
>


Does it cause a problem? The g++ driver automatically links to libstdc++
and that depends on libc, so the -lc argument has to be after -lstdc++.
Otherwise for static linking the linker could open libc.a before it knows
about the symbols that libstdc++.a needs from it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: G++ driver missing option when sending to collect2
  2021-02-25  7:23 ` Jonathan Wakely
@ 2021-02-26  1:57   ` Yeting Kuo
  0 siblings, 0 replies; 5+ messages in thread
From: Yeting Kuo @ 2021-02-26  1:57 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

There is a command like 'g++ -nostartfiles -Wl,--start-group arduino.ar -lc
-Wl,--end-group ...' would go wrong. `-nostartfiles` makes libc needs some
implements like _init in arduino.ar, but also arduino.ar depends on libc
too. G++ will output an error 'FAIL: undefined reference to _init' when g++
removes the `-lc`.

Jonathan Wakely <jwakely.gcc@gmail.com> 於 2021年2月25日 週四 下午3:23寫道:

>
>
> On Thu, 25 Feb 2021, 02:46 Yeting Kuo via Gcc-help, <gcc-help@gcc.gnu.org>
> wrote:
>
>> Hi all,
>> I have a compiler driver issue when using g++. I want to check whether it
>> is a bug.
>> I send '-Wl,--start-group x.o -lc -Wl,--end-group' to g++, but the command
>> collect2 received is '--start-group x.o --end-group' like the following
>> commands:
>>
>
>
> Does it cause a problem? The g++ driver automatically links to libstdc++
> and that depends on libc, so the -lc argument has to be after -lstdc++.
> Otherwise for static linking the linker could open libc.a before it knows
> about the symbols that libstdc++.a needs from it.
>
>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: G++ driver missing option when sending to collect2
  2021-02-25  2:13 G++ driver missing option when sending to collect2 Yeting Kuo
  2021-02-25  7:23 ` Jonathan Wakely
@ 2021-02-26 19:15 ` Jim Wilson
  2021-03-02 11:41   ` Yeting Kuo
  1 sibling, 1 reply; 5+ messages in thread
From: Jim Wilson @ 2021-02-26 19:15 UTC (permalink / raw)
  To: Yeting Kuo; +Cc: gcc-help

On Wed, Feb 24, 2021 at 6:13 PM Yeting Kuo via Gcc-help <
gcc-help@gcc.gnu.org> wrote:

> $ riscv32-unknown-elf-g++ test.o -Wl,--start-group x.o -lc -Wl,--end-group
> -v
>

If you make all of the options linker options instead of compiler options,
then the compiler won't re-sort them.  E.g. this works
    riscv32-unknown-elf-g++ test.o -Wl,--start-group -Wl,x.o -Wl,-lc
-Wl,--end-group -v

However, if you have some special library that requires special treatment,
it is probably better to encode that in the specs.  If this is for a
special target triplet, then you can modify the LINK_SPEC for the target in
the gcc sources.  Otherwise, you can try using a modified specs file.  You
can use
    riscv32-unknown-elf-gcc -dumpspecs > specs
to see the default specs file.  You can provide an incremental specs file
to modify lib or link_command or whatever is appropriate for your target.
You can then specify the specs file when linking with -specs=yourspecfile.
Or you can modify the default specs file and then copy it into the same dir
where cc1 lives if you want it used for all compilers.  You can find an
example of how to do this incrementally in libgloss.

https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/riscv/nano.specs;h=e12e31384241c58a5a07341a0f7cebc4fac9ed20;hb=HEAD
When using riscv-gnu-toolchain and adding -specs=nano.specs we link with
-lc_nano instead of -lc.  A simpler example might just be appending an
extra library to lib.

Jim

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: G++ driver missing option when sending to collect2
  2021-02-26 19:15 ` Jim Wilson
@ 2021-03-02 11:41   ` Yeting Kuo
  0 siblings, 0 replies; 5+ messages in thread
From: Yeting Kuo @ 2021-03-02 11:41 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc-help

Hi Jim,
Thanks your advice. It helps me a lot.

Best Regard,
Yeting Kuo

Jim Wilson <jimw@sifive.com> 於 2021年2月27日 週六 上午3:16寫道:

> On Wed, Feb 24, 2021 at 6:13 PM Yeting Kuo via Gcc-help <
> gcc-help@gcc.gnu.org> wrote:
>
>> $ riscv32-unknown-elf-g++ test.o -Wl,--start-group x.o -lc -Wl,--end-group
>> -v
>>
>
> If you make all of the options linker options instead of compiler options,
> then the compiler won't re-sort them.  E.g. this works
>     riscv32-unknown-elf-g++ test.o -Wl,--start-group -Wl,x.o -Wl,-lc
> -Wl,--end-group -v
>
> However, if you have some special library that requires special treatment,
> it is probably better to encode that in the specs.  If this is for a
> special target triplet, then you can modify the LINK_SPEC for the target in
> the gcc sources.  Otherwise, you can try using a modified specs file.  You
> can use
>     riscv32-unknown-elf-gcc -dumpspecs > specs
> to see the default specs file.  You can provide an incremental specs file
> to modify lib or link_command or whatever is appropriate for your target.
> You can then specify the specs file when linking with -specs=yourspecfile.
> Or you can modify the default specs file and then copy it into the same dir
> where cc1 lives if you want it used for all compilers.  You can find an
> example of how to do this incrementally in libgloss.
>
> https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/riscv/nano.specs;h=e12e31384241c58a5a07341a0f7cebc4fac9ed20;hb=HEAD
> When using riscv-gnu-toolchain and adding -specs=nano.specs we link with
> -lc_nano instead of -lc.  A simpler example might just be appending an
> extra library to lib.
>
> Jim
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-02 11:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-25  2:13 G++ driver missing option when sending to collect2 Yeting Kuo
2021-02-25  7:23 ` Jonathan Wakely
2021-02-26  1:57   ` Yeting Kuo
2021-02-26 19:15 ` Jim Wilson
2021-03-02 11:41   ` Yeting Kuo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).