llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: bd1976bris (bd1976bris) <details> <summary>Changes</summary> Adjust the PS5 driver defaults for the `-fvisibility-from-dllstorageclass` sub-options so that only globals with dllimport/dllexport annotations are adjusted. This allows globals without dllimport/export to retain the visibility and pre-emptability assigned during IR-Gen. Set `-fvisibility=hidden` on PS5 by default to compensate for no longer overriding the visibility of definitions without dllexport. Note there is no behaviour change for PS4 (the behaviour of overriding the visibility for all globals is retained on PS4). --- Full diff: https://github.com/llvm/llvm-project/pull/92091.diff 4 Files Affected: - (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+16-2) - (modified) clang/test/Driver/ps4-ps5-visibility-dllstorageclass.c (+26-13) - (added) clang/test/Driver/ps4-visibility.cl (+32) - (added) clang/test/Driver/ps5-visibility.cl (+33) ``````````diff diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp index 7bf9aa79384c5..3fd62d9793093 100644 --- a/clang/lib/Driver/ToolChains/PS4CPU.cpp +++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp @@ -358,6 +358,12 @@ void toolchains::PS4PS5Base::addClangTargetOptions( CC1Args.push_back("-fno-use-init-array"); + // Default to `hidden` visibility for PS5. + if (getTriple().isPS5() && + !DriverArgs.hasArg(options::OPT_fvisibility_EQ, + options::OPT_fvisibility_ms_compat)) + CC1Args.push_back("-fvisibility=hidden"); + // Default to -fvisibility-global-new-delete=source for PS5. if (getTriple().isPS5() && !DriverArgs.hasArg(options::OPT_fvisibility_global_new_delete_EQ, @@ -376,11 +382,15 @@ void toolchains::PS4PS5Base::addClangTargetOptions( else CC1Args.push_back("-fvisibility-dllexport=protected"); + // For PS4 we override the visibilty of globals definitions without + // dllimport or dllexport annotations. if (DriverArgs.hasArg(options::OPT_fvisibility_nodllstorageclass_EQ)) DriverArgs.AddLastArg(CC1Args, options::OPT_fvisibility_nodllstorageclass_EQ); - else + else if (getTriple().isPS4()) CC1Args.push_back("-fvisibility-nodllstorageclass=hidden"); + else + CC1Args.push_back("-fvisibility-nodllstorageclass=keep"); if (DriverArgs.hasArg(options::OPT_fvisibility_externs_dllimport_EQ)) DriverArgs.AddLastArg(CC1Args, @@ -388,12 +398,16 @@ void toolchains::PS4PS5Base::addClangTargetOptions( else CC1Args.push_back("-fvisibility-externs-dllimport=default"); + // For PS4 we override the visibilty of external globals without + // dllimport or dllexport annotations. if (DriverArgs.hasArg( options::OPT_fvisibility_externs_nodllstorageclass_EQ)) DriverArgs.AddLastArg( CC1Args, options::OPT_fvisibility_externs_nodllstorageclass_EQ); - else + else if (getTriple().isPS4()) CC1Args.push_back("-fvisibility-externs-nodllstorageclass=default"); + else + CC1Args.push_back("-fvisibility-externs-nodllstorageclass=keep"); } } diff --git a/clang/test/Driver/ps4-ps5-visibility-dllstorageclass.c b/clang/test/Driver/ps4-ps5-visibility-dllstorageclass.c index 430827805a8fd..71f8661679eb7 100644 --- a/clang/test/Driver/ps4-ps5-visibility-dllstorageclass.c +++ b/clang/test/Driver/ps4-ps5-visibility-dllstorageclass.c @@ -1,16 +1,19 @@ // Check behaviour of -fvisibility-from-dllstorageclass options for PS4/PS5. // DEFINE: %{triple} = +// DEFINE: %{prefix} = // DEFINE: %{run} = \ // DEFINE: %clang -### -target %{triple} %s -Werror -o - 2>&1 | \ -// DEFINE: FileCheck %s --check-prefix=DEFAULTS \ +// DEFINE: FileCheck %s --check-prefixes=DEFAULTS,%{prefix} \ // DEFINE: --implicit-check-not=-fvisibility-from-dllstorageclass \ // DEFINE: --implicit-check-not=-fvisibility-dllexport \ // DEFINE: --implicit-check-not=-fvisibility-nodllstorageclass \ // DEFINE: --implicit-check-not=-fvisibility-externs-dllimport \ // DEFINE: --implicit-check-not=-fvisibility-externs-nodllstorageclass +// REDEFINE: %{prefix} = DEFAULTS-PS4 // REDEFINE: %{triple} = x86_64-scei-ps4 // RUN: %{run} +// REDEFINE: %{prefix} = DEFAULTS-PS5 // REDEFINE: %{triple} = x86_64-sie-ps5 // RUN: %{run} // @@ -20,25 +23,29 @@ // REDEFINE: -fvisibility-from-dllstorageclass \ // REDEFINE: -Werror \ // REDEFINE: %s -o - 2>&1 | \ -// REDEFINE: FileCheck %s --check-prefix=DEFAULTS \ +// REDEFINE: FileCheck %s --check-prefixes=DEFAULTS,%{prefix} \ // REDEFINE: --implicit-check-not=-fvisibility-from-dllstorageclass \ // REDEFINE: --implicit-check-not=-fvisibility-dllexport \ // REDEFINE: --implicit-check-not=-fvisibility-nodllstorageclass \ // REDEFINE: --implicit-check-not=-fvisibility-externs-dllimport \ // REDEFINE: --implicit-check-not=-fvisibility-externs-nodllstorageclass +// REDEFINE: %{prefix} = DEFAULTS-PS4 // REDEFINE: %{triple} = x86_64-scei-ps4 // RUN: %{run} +// REDEFINE: %{prefix} = DEFAULTS-PS5 // REDEFINE: %{triple} = x86_64-sie-ps5 // RUN: %{run} // DEFAULTS: "-fvisibility-from-dllstorageclass" // DEFAULTS-SAME: "-fvisibility-dllexport=protected" -// DEFAULTS-SAME: "-fvisibility-nodllstorageclass=hidden" +// DEFAULTS-PS4-SAME: "-fvisibility-nodllstorageclass=hidden" +// DEFAULTS-PS5-SAME: "-fvisibility-nodllstorageclass=keep" // DEFAULTS-SAME: "-fvisibility-externs-dllimport=default" -// DEFAULTS-SAME: "-fvisibility-externs-nodllstorageclass=default" +// DEFAULTS-PS4-SAME: "-fvisibility-externs-nodllstorageclass=default" +// DEFAULTS-PS5-SAME: "-fvisibility-externs-nodllstorageclass=keep" // REDEFINE: %{run} = \ -// REDEFINE: %clang -### -target x86_64-scei-ps4 \ +// REDEFINE: %clang -### -target %{triple} \ // REDEFINE: -fvisibility-from-dllstorageclass \ // REDEFINE: -fvisibility-dllexport=hidden \ // REDEFINE: -fvisibility-nodllstorageclass=protected \ @@ -64,37 +71,41 @@ // UNUSED-NEXT: warning: argument unused during compilation: '-fvisibility-externs-nodllstorageclass=protected' // REDEFINE: %{run} = \ -// REDEFINE: %clang -### -target x86_64-scei-ps4 \ +// REDEFINE: %clang -### -target %{triple} \ // REDEFINE: -fvisibility-nodllstorageclass=protected \ // REDEFINE: -fvisibility-externs-dllimport=hidden \ // REDEFINE: -Werror \ // REDEFINE: %s -o - 2>&1 | \ -// REDEFINE: FileCheck %s -check-prefix=SOME \ +// REDEFINE: FileCheck %s -check-prefixes=SOME,%{prefix} \ // REDEFINE: --implicit-check-not=-fvisibility-from-dllstorageclass \ // REDEFINE: --implicit-check-not=-fvisibility-dllexport \ // REDEFINE: --implicit-check-not=-fvisibility-nodllstorageclass \ // REDEFINE: --implicit-check-not=-fvisibility-externs-dllimport \ // REDEFINE: --implicit-check-not=-fvisibility-externs-nodllstorageclass +// REDEFINE: %{prefix} = SOME-PS4 // REDEFINE: %{triple} = x86_64-scei-ps4 // RUN: %{run} +// REDEFINE: %{prefix} = SOME-PS5 // REDEFINE: %{triple} = x86_64-sie-ps5 // RUN: %{run} // REDEFINE: %{run} = \ -// REDEFINE: %clang -### -target x86_64-scei-ps4 \ +// REDEFINE: %clang -### -target %{triple} \ // REDEFINE: -fvisibility-from-dllstorageclass \ // REDEFINE: -fvisibility-nodllstorageclass=protected \ // REDEFINE: -fvisibility-externs-dllimport=hidden \ // REDEFINE: -Werror \ // REDEFINE: %s -o - 2>&1 | \ -// REDEFINE: FileCheck %s -check-prefix=SOME \ +// REDEFINE: FileCheck %s -check-prefixes=SOME,%{prefix} \ // REDEFINE: --implicit-check-not=-fvisibility-from-dllstorageclass \ // REDEFINE: --implicit-check-not=-fvisibility-dllexport \ // REDEFINE: --implicit-check-not=-fvisibility-nodllstorageclass \ // REDEFINE: --implicit-check-not=-fvisibility-externs-dllimport \ // REDEFINE: --implicit-check-not=-fvisibility-externs-nodllstorageclass +// REDEFINE: %{prefix} = SOME-PS4 // REDEFINE: %{triple} = x86_64-scei-ps4 // RUN: %{run} +// REDEFINE: %{prefix} = SOME-PS5 // REDEFINE: %{triple} = x86_64-sie-ps5 // RUN: %{run} @@ -102,10 +113,11 @@ // SOME-SAME: "-fvisibility-dllexport=protected" // SOME-SAME: "-fvisibility-nodllstorageclass=protected" // SOME-SAME: "-fvisibility-externs-dllimport=hidden" -// SOME-SAME: "-fvisibility-externs-nodllstorageclass=default" +// SOME-PS4-SAME: "-fvisibility-externs-nodllstorageclass=default" +// SOME-PS5-SAME: "-fvisibility-externs-nodllstorageclass=keep" // REDEFINE: %{run} = \ -// REDEFINE: %clang -### -target x86_64-scei-ps4 \ +// REDEFINE: %clang -### -target %{triple} \ // REDEFINE: -fvisibility-dllexport=default \ // REDEFINE: -fvisibility-dllexport=hidden \ // REDEFINE: -fvisibility-nodllstorageclass=default \ @@ -121,14 +133,15 @@ // REDEFINE: --implicit-check-not=-fvisibility-dllexport \ // REDEFINE: --implicit-check-not=-fvisibility-nodllstorageclass \ // REDEFINE: --implicit-check-not=-fvisibility-externs-dllimport \ -// REDEFINE: --implicit-check-not=-fvisibility-externs-nodllstorageclass +// REDEFINE: --implicit-check-not=-fvisibility-externs-nodllstorageclass \ +// REDEFINE: --implicit-check-not="warning: argument unused" // REDEFINE: %{triple} = x86_64-scei-ps4 // RUN: %{run} // REDEFINE: %{triple} = x86_64-sie-ps5 // RUN: %{run} // REDEFINE: %{run} = \ -// REDEFINE: %clang -### -target x86_64-scei-ps4 \ +// REDEFINE: %clang -### -target %{triple} \ // REDEFINE: -fvisibility-from-dllstorageclass \ // REDEFINE: -fvisibility-dllexport=default \ // REDEFINE: -fvisibility-dllexport=hidden \ diff --git a/clang/test/Driver/ps4-visibility.cl b/clang/test/Driver/ps4-visibility.cl new file mode 100644 index 0000000000000..a0ed7c71f1f0e --- /dev/null +++ b/clang/test/Driver/ps4-visibility.cl @@ -0,0 +1,32 @@ +/// Check PS4 specific interactions between visibility options. +/// Detailed testing of -fvisibility-from-dllstorageclass is covered elsewhere. + +/// Check defaults. +// RUN: %clang -### -target x86_64-scei-ps4 -x cl -c -emit-llvm %s 2>&1 | \ +// RUN: FileCheck -check-prefix=DEFAULT %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// DEFAULT-DAG: "-fvisibility-from-dllstorageclass" +// DEFAULT-DAG: "-fvisibility-dllexport=protected" +// DEFAULT-DAG: "-fvisibility-nodllstorageclass=hidden" +// DEFAULT-DAG: "-fvisibility-externs-dllimport=default" +// DEFAULT-DAG: "-fvisibility-externs-nodllstorageclass=default" + +/// Check that -fvisibility-from-dllstorageclass is added in the presence of -fvisibility=. +// RUN: %clang -### -target x86_64-scei-ps4 -x cl -c -emit-llvm -fvisibility=default %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=DEFAULT,VISEQUALS %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// VISEQUALS-DAG: "-fvisibility=default" + +/// Check that -fvisibility-from-dllstorageclass is added in the presence of -fvisibility-ms-compat. +// RUN: %clang -### -target x86_64-scei-ps4 -x cl -c -emit-llvm -fvisibility-ms-compat %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=DEFAULT,MSCOMPT %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// MSCOMPT-DAG: "-fvisibility=hidden" +// MSCOMPT-DAG: "-ftype-visibility=default" + +/// -fvisibility-from-dllstorageclass added explicitly. +// RUN: %clang -### -target x86_64-scei-ps4 -x cl -c -emit-llvm -fvisibility-from-dllstorageclass %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=DEFAULT %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass + +/// -fvisibility-from-dllstorageclass disabled explicitly. +// RUN: %clang -### -target x86_64-scei-ps4 -x cl -c -emit-llvm -fno-visibility-from-dllstorageclass %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=NOVISFROM %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// NOVISFROM-NOT: "-fvisibility-from-dllstorageclass" + diff --git a/clang/test/Driver/ps5-visibility.cl b/clang/test/Driver/ps5-visibility.cl new file mode 100644 index 0000000000000..ad144057be63a --- /dev/null +++ b/clang/test/Driver/ps5-visibility.cl @@ -0,0 +1,33 @@ +/// Check PS5 specific interactions between visibility options. +/// Detailed testing of -fvisibility-from-dllstorageclass is covered elsewhere. + +/// Check defaults. +// RUN: %clang -### -target x86_64-sie-ps5 -x cl -c -emit-llvm %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=VDEFAULT,VGND_DEFAULT,DEFAULT %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// VDEFAULT-DAG: "-fvisibility=hidden" +// VGND_DEFAULT-DAG: "-fvisibility-global-new-delete=source" +// DEFAULT-DAG: "-fvisibility-from-dllstorageclass" +// DEFAULT-DAG: "-fvisibility-dllexport=protected" +// DEFAULT-DAG: "-fvisibility-nodllstorageclass=keep" +// DEFAULT-DAG: "-fvisibility-externs-dllimport=default" +// DEFAULT-DAG: "-fvisibility-externs-nodllstorageclass=keep" + +/// -fvisibility= specified explicitly. +// RUN: %clang -### -target x86_64-sie-ps5 -x cl -c -emit-llvm -fvisibility=protected %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=VPROTECTED,VGND_DEFAULT,DEFAULT %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// VPROTECTED-DAG: "-fvisibility=protected" + +/// -fvisibility-ms-compat added explicitly. +// RUN: %clang -### -target x86_64-sie-ps5 -x cl -c -emit-llvm -fvisibility-ms-compat %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=MSCOMPT,VGND_DEFAULT,DEFAULT %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// MSCOMPT-DAG: "-fvisibility=hidden" +// MSCOMPT-DAG: "-ftype-visibility=default" + +/// -fvisibility-from-dllstorageclass added explicitly. +// RUN: %clang -### -target x86_64-sie-ps5 -x cl -c -emit-llvm -fvisibility-from-dllstorageclass %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=VDEFAULT,VGND_DEFAULT,DEFAULT %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass + +/// -fvisibility-from-dllstorageclass disabled explicitly. +// RUN: %clang -### -target x86_64-sie-ps5 -x cl -c -emit-llvm -fno-visibility-from-dllstorageclass %s 2>&1 | \ +// RUN: FileCheck -check-prefixes=VDEFAULT,VGND_DEFAULT,NOVISFROM %s --implicit-check-not=fvisibility --implicit-check-not=ftype-visibility --implicit-check-not=dllstorageclass +// NOVISFROM-NOT: "-fvisibility-from-dllstorageclass" `````````` </details> https://github.com/llvm/llvm-project/pull/92091 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits