@@ -633,6 +633,7 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
633
633
std::optional<u64 > shuffle_sections_seed;
634
634
std::unordered_set<std::string_view> rpaths;
635
635
std::vector<std::string_view> version_scripts;
636
+ int state_stack_depth = 0 ;
636
637
637
638
auto add_rpath = [&](std::string_view arg) {
638
639
if (rpaths.insert (arg).second ) {
@@ -837,10 +838,14 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
837
838
} else if (read_flag (" print-map" ) || read_flag (" M" )) {
838
839
ctx.arg .print_map = true ;
839
840
} else if (read_flag (" Bstatic" ) || read_flag (" dn" ) || read_flag (" static" )) {
840
- ctx.arg .static_ = true ;
841
+ if (state_stack_depth == 0 )
842
+ ctx.arg .static_ = true ;
843
+
841
844
remaining.emplace_back (" --Bstatic" );
842
845
} else if (read_flag (" Bdynamic" ) || read_flag (" dy" )) {
843
- ctx.arg .static_ = false ;
846
+ if (state_stack_depth == 0 )
847
+ ctx.arg .static_ = false ;
848
+
844
849
remaining.emplace_back (" --Bdynamic" );
845
850
} else if (read_flag (" shared" ) || read_flag (" Bshareable" )) {
846
851
ctx.arg .shared = true ;
@@ -1417,8 +1422,10 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
1417
1422
} else if (read_arg (" script" ) || read_arg (" T" )) {
1418
1423
remaining.emplace_back (arg);
1419
1424
} else if (read_flag (" push-state" )) {
1425
+ state_stack_depth++;
1420
1426
remaining.emplace_back (" --push-state" );
1421
1427
} else if (read_flag (" pop-state" )) {
1428
+ state_stack_depth--;
1422
1429
remaining.emplace_back (" --pop-state" );
1423
1430
} else if (args[0 ].starts_with (" -z" ) && args[0 ].size () > 2 ) {
1424
1431
Warn (ctx) << " unknown command line option: " << args[0 ];
0 commit comments