This is PR34567 ("Bug 34567 - lld: unknown argument: --push-state, --pop-state on ubuntu when using asan")
Documentation (https://sourceware.org/binutils/docs/ld/Options.html) specifies these options as:
--push-state
The --push-state allows to preserve the current state of the flags which govern the input file handling so that they can all be restored with one corresponding --pop-state option.
The option which are covered are: -Bdynamic, -Bstatic, -dn, -dy, -call_shared, -non_shared, -static, -N, -n, --whole-archive, --no-whole-archive, -r, -Ur, --copy-dt-needed-entries, --no-copy-dt-needed-entries, --as-needed, --no-as-needed, and -a.
--pop-state
Undoes the effect of –push-state, restores the previous values of the flags governing input file handling.
gold implementation was: https://sourceware.org/bugzilla/show_bug.cgi?id=18989.
Unlike said in specification, gold preserves only position-dependent options. And that behavior looks correct for me,
I do not see any reasons to preserve/restore position-independent options. Also gold implements real stack with nesting to any depth.
I do not think we really need to do that, at least until bfd does not supports the same.
This patch implements probably simplest way I can imagine.