public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/115698] New: @file invalidates -B in g++ command line
@ 2024-06-28 10:47 yhdang at stu dot xjtu.edu.cn
  2024-06-28 20:51 ` [Bug driver/115698] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: yhdang at stu dot xjtu.edu.cn @ 2024-06-28 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115698

            Bug ID: 115698
           Summary: @file invalidates -B in g++ command line
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yhdang at stu dot xjtu.edu.cn
  Target Milestone: ---

libhugetlbfs (https://github.com/libhugetlbfs/libhugetlbfs) provides the users
with a fancy wrapper of `ld` to enable a few new linker options, such as
`--hugetlbfs-align`. Therefore, it suggests the users to use `-B` to allow
`g++` search the linker in a custom directory:

```
$ ls /usr/local/share/libhugetlbfs
ld  ld.hugetlbfs  ldscripts

$ file /usr/local/share/libhugetlbfs/ld
/usr/local/share/libhugetlbfs/ld: symbolic link to ld.hugetlbfs

$ file /usr/local/share/libhugetlbfs/ld.hugetlbfs 
/usr/local/share/libhugetlbfs/ld.hugetlbfs: Bourne-Again shell script, ASCII
text executable
```

However, the `@file` syntax seems to have `g++` ignore `-B` in the command
line. Specifically, this will work:

```
$ g++ -o main main_binary_auto.o binary.o -B /usr/local/share/libhugetlbfs
-Wl,--no-as-needed -Wl,--hugetlbfs-align -Wl,--rpath=/usr/local/lib64
```

While this gives the following error:

```
$ echo 'main_binary_auto.o binary.o' > file
$ g++ -o main @file -B /usr/local/share/libhugetlbfs -Wl,--no-as-needed
-Wl,--hugetlbfs-align
/usr/bin/ld: unrecognized option '--hugetlbfs-align'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
```

I suspect this is because `@file` syntax somehow cause the `g++` to ignore
`-B`, and thus the original `ld`, instead of the script is picked, so it won't
recognize the new options. 

The output of `g++ --verbose` and `g++ -Wl,--verbose` does not give much useful
information so they are not listed here.

I'm using g++-13 (Ubuntu 13.1.0-8ubuntu1~20.04.2) 13.1.0, and g++ 9.4.0 also
has  this issue.

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

* [Bug driver/115698] @file invalidates -B in g++ command line
  2024-06-28 10:47 [Bug driver/115698] New: @file invalidates -B in g++ command line yhdang at stu dot xjtu.edu.cn
@ 2024-06-28 20:51 ` pinskia at gcc dot gnu.org
  2024-06-28 20:59 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-28 20:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115698

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So I looked into the driver code and '@' handling is early on and just expands
into the new arguments.

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

* [Bug driver/115698] @file invalidates -B in g++ command line
  2024-06-28 10:47 [Bug driver/115698] New: @file invalidates -B in g++ command line yhdang at stu dot xjtu.edu.cn
  2024-06-28 20:51 ` [Bug driver/115698] " pinskia at gcc dot gnu.org
@ 2024-06-28 20:59 ` pinskia at gcc dot gnu.org
  2024-06-30  2:25 ` yhdang at stu dot xjtu.edu.cn
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-28 20:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115698

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-06-28
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I also just tried it with the upstream version of GCC:
```
[apinski@xeond2 upstream-gcc-new]$ ~/upstream-gcc-new/bin/gcc @re -B mydir/
my ld
[apinski@xeond2 upstream-gcc-new]$ cat mydir/ld
#!/bin/bash

echo my ld
exit 0
[apinski@xeond2 upstream-gcc-new]$ ~/upstream-gcc-new/bin/gcc @re -B
`pwd`/mydir/
my ld
[apinski@xeond2 upstream-gcc-new]$ !ch
chmod u+x mydir/ld
[apinski@xeond2 upstream-gcc-new]$ cat re
t.o
[apinski@xeond2 upstream-gcc-new]$ ~/upstream-gcc-new/bin/g++ @re -B
`pwd`/mydir/
my ld
[apinski@xeond2 upstream-gcc-new]$ ~/upstream-gcc-new/bin/g++ -o tt @re -B
`pwd`/mydir/
my ld
```

Works for me.

Try to doing strace to see if the B directories are searched.  

I even tried ubuntu's 11.4.0 and it worked:
```
apinski@xeond:~/src/upstream-gcc-new$ ~/upstream-gcc-match/bin/gcc -o tttt @re
-B `pwd`/mydir
my ld
apinski@xeond:~/src/upstream-gcc-new$ gcc -o tttt @re -B `pwd`/mydir
my ld
apinski@xeond:~/src/upstream-gcc-new$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

```

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

* [Bug driver/115698] @file invalidates -B in g++ command line
  2024-06-28 10:47 [Bug driver/115698] New: @file invalidates -B in g++ command line yhdang at stu dot xjtu.edu.cn
  2024-06-28 20:51 ` [Bug driver/115698] " pinskia at gcc dot gnu.org
  2024-06-28 20:59 ` pinskia at gcc dot gnu.org
@ 2024-06-30  2:25 ` yhdang at stu dot xjtu.edu.cn
  2024-06-30  2:33 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: yhdang at stu dot xjtu.edu.cn @ 2024-06-30  2:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115698

--- Comment #3 from Yihan Dang <yhdang at stu dot xjtu.edu.cn> ---
Hello Andrew, thank you very much for your reply! I think I've found the catch:
Change the custom ld script to this:
```
#!/bin/bash

echo "hello from custom ld, arguments are: $*"

filename=$1
filename=${filename:1}
if [ -e "$filename" ]; then
    cat "$filename"
fi

exit 0
```

The one that does NOT use `@file` syntax would print out all arguments right
here:

```
hello from custom ld, arguments are: -plugin
/usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper ...
```

But the one that DOES use it would output something like:
```
hello from custom ld, arguments are: @/tmp/ccMXQbBc
# /tmp/ccMXQbBC contains all arguments as above
```

Since `ld.libhugetlbfs` does not extract argument from `@file`, it cannot
consume the custom argument, and that is fed eventually to original `ld`, where
the arguments are finally extracted.

I wonder if it makes sense to extract the arguments earlier in the toolchain.
The users sometimes want to use custom `ld` script, and I don't think they
should handle `@file` themselves.

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

* [Bug driver/115698] @file invalidates -B in g++ command line
  2024-06-28 10:47 [Bug driver/115698] New: @file invalidates -B in g++ command line yhdang at stu dot xjtu.edu.cn
                   ` (2 preceding siblings ...)
  2024-06-30  2:25 ` yhdang at stu dot xjtu.edu.cn
@ 2024-06-30  2:33 ` pinskia at gcc dot gnu.org
  2024-06-30  2:38 ` pinskia at gcc dot gnu.org
  2024-06-30  5:10 ` yhdang at stu dot xjtu.edu.cn
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-30  2:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115698

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> Since `ld.libhugetlbfs` does not extract argument from `@file`, it cannot
> consume the custom argument, and that is fed eventually to original `ld`,
> where the arguments are finally extracted.

That would be a bug in ld.libhugetlbfs then. Basically the @file is used so the
size of the options does not get too big. The original BFD Ld understands @file
and able to take all and all options there.
Basically ld.libhugetlbfs needs to support @ syntax to extract all options and
then create a new file to pass on to the real ld.

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

* [Bug driver/115698] @file invalidates -B in g++ command line
  2024-06-28 10:47 [Bug driver/115698] New: @file invalidates -B in g++ command line yhdang at stu dot xjtu.edu.cn
                   ` (3 preceding siblings ...)
  2024-06-30  2:33 ` pinskia at gcc dot gnu.org
@ 2024-06-30  2:38 ` pinskia at gcc dot gnu.org
  2024-06-30  5:10 ` yhdang at stu dot xjtu.edu.cn
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-30  2:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115698

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://github.com/libhuget
                   |                            |lbfs/libhugetlbfs/issues/88

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Filed https://github.com/libhugetlbfs/libhugetlbfs/issues/88 for the
libhugetlbfs issue.

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

* [Bug driver/115698] @file invalidates -B in g++ command line
  2024-06-28 10:47 [Bug driver/115698] New: @file invalidates -B in g++ command line yhdang at stu dot xjtu.edu.cn
                   ` (4 preceding siblings ...)
  2024-06-30  2:38 ` pinskia at gcc dot gnu.org
@ 2024-06-30  5:10 ` yhdang at stu dot xjtu.edu.cn
  5 siblings, 0 replies; 7+ messages in thread
From: yhdang at stu dot xjtu.edu.cn @ 2024-06-30  5:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115698

--- Comment #6 from Yihan Dang <yhdang at stu dot xjtu.edu.cn> ---
(In reply to Andrew Pinski from comment #5)
> Filed https://github.com/libhugetlbfs/libhugetlbfs/issues/88 for the
> libhugetlbfs issue.

Thank you very much for the help! I have submitted a pull request to this
issue.

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

end of thread, other threads:[~2024-06-30  5:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-28 10:47 [Bug driver/115698] New: @file invalidates -B in g++ command line yhdang at stu dot xjtu.edu.cn
2024-06-28 20:51 ` [Bug driver/115698] " pinskia at gcc dot gnu.org
2024-06-28 20:59 ` pinskia at gcc dot gnu.org
2024-06-30  2:25 ` yhdang at stu dot xjtu.edu.cn
2024-06-30  2:33 ` pinskia at gcc dot gnu.org
2024-06-30  2:38 ` pinskia at gcc dot gnu.org
2024-06-30  5:10 ` yhdang at stu dot xjtu.edu.cn

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).