From ae9231ca2a8125ce75fff3ff2539126610aa2eeb Mon Sep 17 00:00:00 2001 From: Ben Dunbobbin Date: Mon, 2 Nov 2020 23:24:04 +0000 Subject: Reland - [Clang] Add the ability to map DLL storage class to visibility 415f7ee883 had LIT test failures on any build where the clang executable was not called "clang". I have adjusted the LIT CHECKs to remove the binary name to fix this. Original commit message: For PlayStation we offer source code compatibility with Microsoft's dllimport/export annotations; however, our file format is based on ELF. To support this we translate from DLL storage class to ELF visibility at the end of codegen in Clang. Other toolchains have used similar strategies (e.g. see the documentation for this ARM toolchain: https://developer.arm.com/documentation/dui0530/i/migrating-from-rvct-v3-1-to-rvct-v4-0/changes-to-symbol-visibility-between-rvct-v3-1-and-rvct-v4-0) This patch adds the ability to perform this translation. Options are provided to support customizing the mapping behaviour. Differential Revision: https://reviews.llvm.org/D89970 --- clang/lib/Frontend/CompilerInvocation.cpp | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 3c0ba31..7b8554c 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2814,6 +2814,38 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, if (Args.hasArg(OPT_fapply_global_visibility_to_externs)) Opts.SetVisibilityForExternDecls = 1; + if (Args.hasArg(OPT_fvisibility_from_dllstorageclass)) { + Opts.VisibilityFromDLLStorageClass = 1; + + // Translate dllexport defintions to default visibility, by default. + if (Arg *O = Args.getLastArg(OPT_fvisibility_dllexport_EQ)) + Opts.setDLLExportVisibility(parseVisibility(O, Args, Diags)); + else + Opts.setDLLExportVisibility(DefaultVisibility); + + // Translate defintions without an explict DLL storage class to hidden + // visibility, by default. + if (Arg *O = Args.getLastArg(OPT_fvisibility_nodllstorageclass_EQ)) + Opts.setNoDLLStorageClassVisibility(parseVisibility(O, Args, Diags)); + else + Opts.setNoDLLStorageClassVisibility(HiddenVisibility); + + // Translate dllimport external declarations to default visibility, by + // default. + if (Arg *O = Args.getLastArg(OPT_fvisibility_externs_dllimport_EQ)) + Opts.setExternDeclDLLImportVisibility(parseVisibility(O, Args, Diags)); + else + Opts.setExternDeclDLLImportVisibility(DefaultVisibility); + + // Translate external declarations without an explicit DLL storage class + // to hidden visibility, by default. + if (Arg *O = Args.getLastArg(OPT_fvisibility_externs_nodllstorageclass_EQ)) + Opts.setExternDeclNoDLLStorageClassVisibility( + parseVisibility(O, Args, Diags)); + else + Opts.setExternDeclNoDLLStorageClassVisibility(HiddenVisibility); + } + if (Args.hasArg(OPT_ftrapv)) { Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping); // Set the handler, if one is specified. -- cgit v1.1