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.