[lld] b41b414 - [lld-macho] Only enable `__DATA_CONST` for newer platforms

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 30 15:56:01 PDT 2021


Author: Jez Ng
Date: 2021-06-30T18:55:48-04:00
New Revision: b41b4148e7b9e0cb8482674875449ae3f223cdfe

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

LOG: [lld-macho] Only enable `__DATA_CONST` for newer platforms

Matches ld64.

Reviewed By: #lld-macho, alexander-shaposhnikov

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

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/test/MachO/builtin-rename.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 1d06f19311c1..59f764f8c1d2 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -841,6 +841,20 @@ static std::vector<SectionAlign> parseSectAlign(const opt::InputArgList &args) {
 }
 
 static bool dataConstDefault(const InputArgList &args) {
+  static const std::map<PlatformKind, VersionTuple> minVersion = {
+      {PlatformKind::macOS, VersionTuple(10, 15)},
+      {PlatformKind::iOS, VersionTuple(13, 0)},
+      {PlatformKind::iOSSimulator, VersionTuple(13, 0)},
+      {PlatformKind::tvOS, VersionTuple(13, 0)},
+      {PlatformKind::tvOSSimulator, VersionTuple(13, 0)},
+      {PlatformKind::watchOS, VersionTuple(6, 0)},
+      {PlatformKind::watchOSSimulator, VersionTuple(6, 0)},
+      {PlatformKind::bridgeOS, VersionTuple(4, 0)}};
+  auto it = minVersion.find(config->platformInfo.target.Platform);
+  if (it != minVersion.end())
+    if (config->platformInfo.minimum < it->second)
+      return false;
+
   switch (config->outputType) {
   case MH_EXECUTE:
     return !args.hasArg(OPT_no_pie);

diff  --git a/lld/test/MachO/builtin-rename.s b/lld/test/MachO/builtin-rename.s
index faa003090e83..9191ba7cd5c6 100644
--- a/lld/test/MachO/builtin-rename.s
+++ b/lld/test/MachO/builtin-rename.s
@@ -10,6 +10,7 @@
 # RUN: %lld                -o %t/ydata %t/main.o %t/renames.o -lSystem
 # RUN: %lld -no_data_const -o %t/ndata %t/main.o %t/renames.o -lSystem
 # RUN: %lld -no_pie        -o %t/nopie %t/main.o %t/renames.o -lSystem
+# RUN: %lld -platform_version macos 10.14 11.0 -o %t/old %t/main.o %t/renames.o -lSystem
 
 # RUN: llvm-objdump --syms %t/ydata | \
 # RUN:     FileCheck %s --check-prefixes=CHECK,YDATA
@@ -17,6 +18,8 @@
 # RUN:     FileCheck %s --check-prefixes=CHECK,NDATA
 # RUN: llvm-objdump --syms %t/nopie | \
 # RUN:     FileCheck %s --check-prefixes=CHECK,NDATA
+# RUN: llvm-objdump --syms %t/old | \
+# RUN:     FileCheck %s --check-prefixes=CHECK,NDATA
 
 # CHECK-LABEL: {{^}}SYMBOL TABLE:
 


        


More information about the llvm-commits mailing list