mirror of
https://github.com/rui314/mold.git
synced 2024-12-24 17:01:50 +03:00
Add -push-state and -pop-state
This commit is contained in:
parent
487486c503
commit
fefa083188
@ -379,6 +379,10 @@ void parse_nonpositional_args(std::span<std::string_view> args,
|
||||
remaining.push_back(arg);
|
||||
} else if (read_arg(args, arg, "script") || read_arg(args, arg, "T")) {
|
||||
remaining.push_back(arg);
|
||||
} else if (read_flag(args, "push-state")) {
|
||||
remaining.push_back("-push-state");
|
||||
} else if (read_flag(args, "pop-state")) {
|
||||
remaining.push_back("-pop-state");
|
||||
} else {
|
||||
if (args[0][0] == '-')
|
||||
Fatal() << "mold: unknown command line option: " << args[0];
|
||||
|
9
main.cc
9
main.cc
@ -934,6 +934,8 @@ MemoryMappedFile *find_library(std::string name,
|
||||
|
||||
static void read_input_files(std::span<std::string_view> args,
|
||||
ReadContext &ctx) {
|
||||
std::vector<std::tuple<bool, bool>> state;
|
||||
|
||||
while (!args.empty()) {
|
||||
std::string_view arg;
|
||||
|
||||
@ -945,6 +947,13 @@ static void read_input_files(std::span<std::string_view> args,
|
||||
ctx.whole_archive = true;
|
||||
} else if (read_flag(args, "no-whole-archive")) {
|
||||
ctx.whole_archive = false;
|
||||
} else if (read_flag(args, "push-state")) {
|
||||
state.push_back({ctx.as_needed, ctx.whole_archive});
|
||||
} else if (read_flag(args, "pop-state")) {
|
||||
if (state.empty())
|
||||
Fatal() << "no state pushed before popping";
|
||||
std::tie(ctx.as_needed, ctx.whole_archive) = state.back();
|
||||
state.pop_back();
|
||||
} else if (read_arg(args, arg, "l")) {
|
||||
read_file(find_library(std::string(arg), config.library_paths), ctx);
|
||||
} else {
|
||||
|
27
test/push-pop-state.sh
Executable file
27
test/push-pop-state.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cd $(dirname $0)
|
||||
echo -n "Testing $(basename -s .sh $0) ... "
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | clang -shared -o $t/a.so -xc -
|
||||
int foo = 1;
|
||||
EOF
|
||||
|
||||
cat <<EOF | clang -shared -o $t/b.so -xc -
|
||||
int bar = 1;
|
||||
EOF
|
||||
|
||||
cat <<EOF | clang -c -o $t/c.o -xc -
|
||||
int main() {}
|
||||
EOF
|
||||
|
||||
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.o -Wl,-as-needed \
|
||||
-Wl,-push-state -Wl,-no-as-needed $t/a.so -Wl,-pop-state $t/b.so
|
||||
|
||||
readelf --dynamic $t/exe > $t/log
|
||||
fgrep -q a.so $t/log
|
||||
! fgrep -q b.so $t/log
|
||||
|
||||
echo OK
|
Loading…
Reference in New Issue
Block a user