Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/linker-script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,12 @@ std::string_view Script<E>::get_script_output_type() {
}

if (tok.size() >= 3 && (tok[0] == "INPUT" || tok[0] == "GROUP") &&
tok[1] == "(")
tok[1] == "(") {
if (tok.size() >= 5 && tok[2] == "AS_NEEDED" && tok[3] == "(")
tok = tok.subspan(2);
if (MappedFile *mf = resolve_path(tok[2], false))
return get_machine_type(ctx, rctx, mf);
}
return "";
}

Expand Down
24 changes: 24 additions & 0 deletions test/linker-script-group-as-needed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
. $(dirname $0)/common.inc

cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF

cat <<EOF | $CC -B. -shared -o $t/libB.so -c -xc -
void not_needed() { }
EOF
$AR

cat <<EOF > $t/libscript.a
GROUP(AS_NEEDED("$t/libB.so"))
EOF

$CC -B. -o $t/exe -L$t -lscript $t/a.o
$QEMU $t/exe | grep 'Hello world'

$CC -B. -o $t/exe -L$t -l:libscript.a $t/a.o
$QEMU $t/exe | grep 'Hello world'