[lld] eb6f9f3 - [lld-macho] Fix trailing slash in oso_prefix

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 12 11:39:36 PST 2021


Author: Keith Smiley
Date: 2021-11-12T11:29:08-08:00
New Revision: eb6f9f3123e6043d559fdfd921714626ff542cee

URL: https://github.com/llvm/llvm-project/commit/eb6f9f3123e6043d559fdfd921714626ff542cee
DIFF: https://github.com/llvm/llvm-project/commit/eb6f9f3123e6043d559fdfd921714626ff542cee.diff

LOG: [lld-macho] Fix trailing slash in oso_prefix

Previously if you passed `-oso_prefix path/to/foo/` with a trailing
slash at the end, using `real_path` would remove that slash, but that
slash is necessary to make sure OSO prefix paths end up as valid
relative paths instead of starting with `/`.

Differential Revision: https://reviews.llvm.org/D113541

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/test/MachO/stabs.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 861ba97066754..82914c3835870 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1157,7 +1157,9 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
       // (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();
-      if (config->osoPrefix.equals(".") && !expanded.endswith(sep))
+      // real_path removes trailing slashes as part of the normalization, but
+      // these are meaningful for our text based stripping
+      if (config->osoPrefix.equals(".") || config->osoPrefix.endswith(sep))
         expanded += sep;
       config->osoPrefix = saver.save(expanded.str());
     }

diff  --git a/lld/test/MachO/stabs.s b/lld/test/MachO/stabs.s
index 07dd2e77e9e01..e2ef9daa15720 100644
--- a/lld/test/MachO/stabs.s
+++ b/lld/test/MachO/stabs.s
@@ -54,6 +54,8 @@
 ## when -oso_prefix <path> is used.
 # RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t" -o %t/test-rel
 # RUN: dsymutil -s  %t/test-rel | grep 'N_OSO' | FileCheck %s  -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH
+# RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t/" -o %t/test-rel
+# RUN: dsymutil -s  %t/test-rel | grep 'N_OSO' | FileCheck %s  -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH-NO-SLASH
 # RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "." -o %t/test-rel-dot
 # RUN: dsymutil -s  %t/test-rel-dot | grep 'N_OSO' | FileCheck %s  -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-DOT
 ## Set HOME to %t (for ~ to expand to)
@@ -82,6 +84,7 @@
 # CHECK:      (N_SO         ) 00                         0000   0000000000000000   '/tmp/test.cpp'
 # CHECK-NEXT: (N_OSO        ) 03                         0001   [[#%.16x,TEST_TIME]] '[[DIR]]/test.o'
 # REL-PATH:   (N_OSO        ) 03                         0001   [[#%.16x,TEST_TIME]] '/test.o'
+# REL-PATH-NO-SLASH:  (N_OSO        ) 03                 0001   [[#%.16x,TEST_TIME]] 'test.o'
 # REL-DOT:    (N_OSO        ) 03                         0001   [[#%.16x,TEST_TIME]] 'test.o'
 # CHECK-NEXT: (N_STSYM      ) [[#%.2d,MORE_DATA_ID + 1]] 0000   [[#%.16x,STATIC:]] '_static_var'
 # CHECK-NEXT: (N_FUN        ) [[#%.2d,TEXT_ID + 1]]      0000   [[#%.16x,MAIN:]]   '_main'
@@ -105,8 +108,9 @@
 # CHECK-NEXT: (N_SO         ) 01                         0000   0000000000000000{{$}}
 # CHECK-NEXT: (N_SO         ) 00                         0000   0000000000000000   '/foo.cpp'
 # CHECK-NEXT: (N_OSO        ) 03                         0001   [[#%.16x,FOO_TIME]] '[[FOO_PATH]]'
-# REL-PATH-NEXT:   (N_OSO        ) 03                         0001   [[#%.16x,FOO_TIME]] '/foo.o'
-# REL-DOT-NEXT:    (N_OSO        ) 03                         0001   [[#%.16x,FOO_TIME]] 'foo.o'
+# REL-PATH-NEXT:   (N_OSO        ) 03                    0001   [[#%.16x,FOO_TIME]] '/foo.o'
+# REL-PATH-NO-SLASH-NEXT:   (N_OSO        ) 03           0001   [[#%.16x,FOO_TIME]] 'foo.o'
+# REL-DOT-NEXT:    (N_OSO        ) 03                    0001   [[#%.16x,FOO_TIME]] 'foo.o'
 # CHECK-NEXT: (N_FUN        ) [[#%.2d,TEXT_ID + 1]]      0000   [[#%.16x,FOO:]]    '_foo'
 # CHECK-NEXT: (N_FUN        ) 00                         0000   0000000000000001{{$}}
 # CHECK-NEXT: (N_SO         ) 01                         0000   0000000000000000{{$}}


        


More information about the llvm-commits mailing list