[PATCH] D112291: [lld-macho] Implement -oso_prefix

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 21 19:39:30 PDT 2021


oontvoo created this revision.
Herald added a subscriber: dang.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

https://bugs.llvm.org/show_bug.cgi?id=50229


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112291

Files:
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/Options.td
  lld/MachO/SyntheticSections.cpp
  lld/test/MachO/stabs.s


Index: lld/test/MachO/stabs.s
===================================================================
--- lld/test/MachO/stabs.s
+++ lld/test/MachO/stabs.s
@@ -50,6 +50,12 @@
 # RUN:   FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.o \
 # RUN:       -D#TEST_TIME=0x10 -D#FOO_TIME=0x20
 
+## Check that we emit relative path to object files in OSO entries
+## 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.a no-debug.o -o %t/test
 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
 # RUN:   FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
@@ -65,6 +71,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'
 # 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'
 # CHECK-NEXT: (N_FUN        ) 00                         0000   0000000000000006{{$}}
@@ -87,6 +94,7 @@
 # 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-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{{$}}
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -860,7 +860,11 @@
   if (!file->archiveName.empty())
     path.append({"(", file->getName(), ")"});
 
-  stab.strx = stringTableSection.addString(saver.save(path.str()));
+  StringRef adjustedPath = saver.save(path.str());
+  if (!config->osoPrefix.empty())
+    adjustedPath.consume_front(config->osoPrefix);
+
+  stab.strx = stringTableSection.addString(adjustedPath);
   stab.desc = 1;
   stab.value = file->modTime;
   stabs.emplace_back(std::move(stab));
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -576,7 +576,6 @@
 def oso_prefix : Separate<["-"], "oso_prefix">,
     MetaVarName<"<path>">,
     HelpText<"Remove the prefix <path> from OSO symbols in the debug map">,
-    Flags<[HelpHidden]>,
     Group<grp_symtab>;
 def add_ast_path : Separate<["-"], "add_ast_path">,
     MetaVarName<"<path>">,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1095,6 +1095,13 @@
   depTracker =
       make<DependencyTracker>(args.getLastArgValue(OPT_dependency_info));
 
+  config->osoPrefix = args.getLastArgValue(OPT_oso_prefix);
+  // FIXME:  Expand "." and "~"?
+  // The doc says if "." is specified then it should be expanded to "current
+  // dir". Similarly, "~" for home.
+  // But this flag is usually passed via the clang driver, and I think it
+  // would already have expanded it.
+
   // Must be set before any InputSections and Symbols are created.
   config->deadStrip = args.hasArg(OPT_dead_strip);
 
Index: lld/MachO/Config.h
===================================================================
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -174,6 +174,8 @@
 
   bool zeroModTime = false;
 
+  llvm::StringRef osoPrefix;
+
   llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }
 
   llvm::MachO::PlatformKind platform() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112291.381459.patch
Type: text/x-patch
Size: 4210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211022/65050d63/attachment.bin>


More information about the llvm-commits mailing list