Skip to content

Commit df7b143

Browse files
committed
Fix getting output type from linker scripts that use AS_NEEDED
Make Script<E>::get_script_output_type support AS_NEEDED inside an INPUT or GROUP group, so that the libatomic_asneeded.so linker script used by GCC 16 works. Fixes #1545 Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
1 parent 17956fd commit df7b143

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/linker-script.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,12 @@ std::string_view Script<E>::get_script_output_type() {
249249
}
250250

251251
if (tok.size() >= 3 && (tok[0] == "INPUT" || tok[0] == "GROUP") &&
252-
tok[1] == "(")
252+
tok[1] == "(") {
253+
if (tok[2] == "AS_NEEDED" && tok[3] == "(")
254+
tok = tok.subspan(2);
253255
if (MappedFile *mf = resolve_path(tok[2], false))
254256
return get_machine_type(ctx, rctx, mf);
257+
}
255258
return "";
256259
}
257260

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
. $(dirname $0)/common.inc
3+
4+
cat <<EOF | $CC -o $t/a.o -c -xc -
5+
#include <stdio.h>
6+
int main() {
7+
printf("Hello world\n");
8+
}
9+
EOF
10+
11+
cat <<EOF | $CC -B. -shared -o $t/libB.so -c -xc -
12+
void not_needed() { }
13+
EOF
14+
$AR
15+
16+
cat <<EOF > $t/libscript.a
17+
GROUP(AS_NEEDED("$t/libB.so"))
18+
EOF
19+
20+
$CC -B. -o $t/exe -L$t -lscript $t/a.o
21+
$QEMU $t/exe | grep 'Hello world'
22+
23+
$CC -B. -o $t/exe -L$t -l:libscript.a $t/a.o
24+
$QEMU $t/exe | grep 'Hello world'

0 commit comments

Comments
 (0)