[lld] [lld-macho] Process OSO prefix only textually in both input and output (PR #152063)
Daniel RodrÃguez Troitiño via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 13:13:26 PDT 2025
================
@@ -1635,27 +1635,23 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
config->osoPrefix = args.getLastArgValue(OPT_oso_prefix);
if (!config->osoPrefix.empty()) {
- // Expand special characters, such as ".", "..", or "~", if present.
- // Note: LD64 only expands "." and not other special characters.
- // That seems silly to imitate so we will not try to follow it, but rather
- // just use real_path() to do it.
-
// The max path length is 4096, in theory. However that seems quite long
// and seems unlikely that any one would want to strip everything from the
// path. Hence we've picked a reasonably large number here.
SmallString<1024> expanded;
- if (!fs::real_path(config->osoPrefix, expanded,
- /*expand_tilde=*/true)) {
- // Note: LD64 expands "." to be `<current_dir>/`
- // (ie., it has a slash suffix) whereas real_path() doesn't.
- // So we have to append '/' to be consistent.
- StringRef sep = sys::path::get_separator();
- // real_path removes trailing slashes as part of the normalization, but
- // these are meaningful for our text based stripping
- if (config->osoPrefix == "." || config->osoPrefix.ends_with(sep))
- expanded += sep;
- config->osoPrefix = saver().save(expanded.str());
+ // Expand "." into the current working directory.
+ if (config->osoPrefix == ".") {
+ if (!fs::current_path(expanded)) {
----------------
drodriguez wrote:
About ignoring the error: it is basically the same flow when `fs::real_path` failed in the previous version. Nothing got expanded and the value was used as passed.
However, I think there's a logic difference that I introduced here, because `config->osoPrefix` will be overwritten with an empty `expanded`, so that might be a logic error that I need to fix. Thanks making me look this code more closely.
https://github.com/llvm/llvm-project/pull/152063
More information about the llvm-commits
mailing list