plotfi updated this revision to Diff 221851. plotfi marked 6 inline comments as done. plotfi added a comment.
addressing cindy and saleem's feedback Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63978/new/ https://reviews.llvm.org/D63978 Files: clang/include/clang/Driver/Action.h clang/include/clang/Driver/Options.td clang/include/clang/Driver/Phases.h clang/include/clang/Driver/ToolChain.h clang/include/clang/Driver/Types.def clang/lib/Driver/Action.cpp clang/lib/Driver/CMakeLists.txt clang/lib/Driver/Driver.cpp clang/lib/Driver/Phases.cpp clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/InterfaceStubs.cpp clang/lib/Driver/ToolChains/InterfaceStubs.h clang/lib/Driver/Types.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/test/InterfaceStubs/bad-format.cpp clang/test/InterfaceStubs/class-template-specialization.cpp clang/test/InterfaceStubs/conflict-type.ifs clang/test/InterfaceStubs/driver-test.c clang/test/InterfaceStubs/externstatic.c clang/test/InterfaceStubs/func.ifs clang/test/InterfaceStubs/function-template-specialization.cpp clang/test/InterfaceStubs/inline.c clang/test/InterfaceStubs/merge-conflict-test.c clang/test/InterfaceStubs/object-double.c clang/test/InterfaceStubs/object-float.c clang/test/InterfaceStubs/object.c clang/test/InterfaceStubs/object.cpp clang/test/InterfaceStubs/object.ifs clang/test/InterfaceStubs/template-namespace-function.cpp clang/test/InterfaceStubs/weak.cpp clang/test/lit.cfg.py
Index: clang/test/lit.cfg.py =================================================================== --- clang/test/lit.cfg.py +++ clang/test/lit.cfg.py @@ -26,7 +26,7 @@ # suffixes: A list of file extensions to treat as test files. config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu', - '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs'] + '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs'] # excludes: A list of directories to exclude from the testsuite. The 'Inputs' # subdirectories contain auxiliary inputs for various tests in their parent @@ -61,7 +61,7 @@ tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] tools = [ - 'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt', + 'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt', 'llvm-ifs', ToolSubst('%clang_extdef_map', command=FindTool( 'clang-extdef-mapping'), unresolved='ignore'), ] Index: clang/test/InterfaceStubs/weak.cpp =================================================================== --- clang/test/InterfaceStubs/weak.cpp +++ clang/test/InterfaceStubs/weak.cpp @@ -1,5 +1,5 @@ // REQUIRES: x86-registered-target -// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \ +// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs -emit-merged-ifs \ // RUN: -interface-stub-version=experimental-ifs-v1 %s | \ // RUN: FileCheck %s Index: clang/test/InterfaceStubs/template-namespace-function.cpp =================================================================== --- clang/test/InterfaceStubs/template-namespace-function.cpp +++ clang/test/InterfaceStubs/template-namespace-function.cpp @@ -1,5 +1,5 @@ // REQUIRES: x86-registered-target -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ +// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -emit-merged-ifs \ // RUN: -interface-stub-version=experimental-ifs-v1 %s | \ // RUN: FileCheck %s Index: clang/test/InterfaceStubs/object.ifs =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/object.ifs @@ -0,0 +1,28 @@ +# RUN: %clang -emit-interface-stubs -o - -emit-merged-ifs %s | \ +# RUN: FileCheck %s --check-prefixes=CHECK-IFS + +# RUN: %clang -emit-interface-stubs -o - %s | llvm-readelf --all | \ +# RUN: FileCheck %s --check-prefixes=CHECK-ELF + +# CHECK-IFS: --- !experimental-ifs-v1 +# CHECK-IFS-NEXT: IfsVersion: 1.0 +# CHECK-IFS-NEXT: Triple: x86_64-linux-gnu +# CHECK-IFS-NEXT: ObjectFileFormat: ELF +# CHECK-IFS-NEXT: Symbols: +# CHECK-IFS-NEXT: b: { Type: Object, Size: 4 } +# CHECK-IFS-NEXT: ... + +# CHECK-ELF: ELF Header: +# CHECK-ELF: Class: ELF64 +# CHECK-ELF: Data: 2's complement, little endian +# CHECK-ELF: Type: DYN (Shared object file) +# CHECK-ELF-NOT: FUNC GLOBAL DEFAULT 1 a +# CHECK-ELF: OBJECT GLOBAL DEFAULT 1 b + +--- !experimental-ifs-v1 +IfsVersion: 1.0 +Triple: x86_64-linux-gnu +ObjectFileFormat: ELF +Symbols: + b: { Type: Object, Size: 4 } +... Index: clang/test/InterfaceStubs/object.cpp =================================================================== --- clang/test/InterfaceStubs/object.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// REQUIRES: x86-registered-target -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 %s | \ -// RUN: FileCheck -check-prefix=CHECK-TAPI %s - -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 %s | \ -// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \ -// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s - -// CHECK-TAPI: data: { Type: Object, Size: 4 } -// CHECK-SYMBOLS: data -int data = 42; Index: clang/test/InterfaceStubs/object.c =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/object.c @@ -0,0 +1,7 @@ +// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck -check-prefix=CHECK-TAPI %s +// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck -check-prefix=CHECK-SYMBOLS %s +// RUN: %clang -c -o - %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s + +// CHECK-TAPI: data: { Type: Object, Size: 4 } +// CHECK-SYMBOLS: data +int data = 42; Index: clang/test/InterfaceStubs/object-float.c =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/object-float.c @@ -0,0 +1,3 @@ +// RUN: not %clang -o - -emit-interface-stubs %s %S/object.c 2>&1 | FileCheck %s +// CHECK: error: Interface Stub: Size Mismatch +double data = 42.0; \ No newline at end of file Index: clang/test/InterfaceStubs/object-double.c =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/object-double.c @@ -0,0 +1,5 @@ +// RUN: not %clang -o - -emit-interface-stubs %s %S/object.c 2>&1 | FileCheck %s +// Need to encode more type info or weak vs strong symbol resolution in llvm-ifs +// XFAIL: * +// CHECK: error: Interface Stub: Size Mismatch +float data = 42.0; \ No newline at end of file Index: clang/test/InterfaceStubs/merge-conflict-test.c =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/merge-conflict-test.c @@ -0,0 +1,3 @@ +// RUN: not %clang -o libfoo.so -emit-interface-stubs %s %S/driver-test.c 2>&1 | FileCheck %s +// CHECK: error: Interface Stub: Type Mismatch +int foo; \ No newline at end of file Index: clang/test/InterfaceStubs/inline.c =================================================================== --- clang/test/InterfaceStubs/inline.c +++ clang/test/InterfaceStubs/inline.c @@ -1,37 +1,32 @@ // REQUIRES: x86-registered-target -// RUN: %clang -DINLINE=inline -target x86_64-unknown-linux-gnu -o - \ -// RUN: -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -std=gnu89 -xc %s | \ +// RUN: %clang -c -DINLINE=inline -target x86_64-unknown-linux-gnu -o - \ +// RUN: -emit-interface-stubs -std=gnu89 -xc %s | \ // RUN: FileCheck -check-prefix=CHECK-GNU %s // RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -O0 -o - -c \ // RUN: -std=gnu89 -xc %s | llvm-nm - | FileCheck -check-prefix=CHECK-GNU %s -// RUN: %clang -DINLINE="__attribute__((always_inline))" \ -// RUN: -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -xc %s | \ +// RUN: %clang -c -DINLINE="__attribute__((always_inline))" \ +// RUN: -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -xc %s | \ // RUN: FileCheck -check-prefix=CHECK-GNU %s // RUN: %clang -DINLINE="__attribute__((always_inline))" \ // RUN: -target x86_64-linux-gnu -O0 -o - -c -xc %s | \ // RUN: llvm-nm - | FileCheck -check-prefix=CHECK-GNU %s -// RUN: %clang -DINLINE=inline -target x86_64-unknown-linux-gnu -o - \ -// RUN: -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -std=c99 -xc %s | \ +// RUN: %clang -c -DINLINE=inline -target x86_64-unknown-linux-gnu -o - \ +// RUN: -emit-interface-stubs -std=c99 -xc %s | \ // RUN: FileCheck -check-prefix=CHECK-STD %s // RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -O0 -o - -c -std=c99 \ // RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-STD %s -// RUN: %clang -DINLINE="__attribute__((noinline))" \ -// RUN: -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -std=c99 -xc %s | \ +// RUN: %clang -c -DINLINE="__attribute__((noinline))" \ +// RUN: -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -std=c99 -xc %s | \ // RUN: FileCheck -check-prefix=CHECK-NOINLINE %s // RUN: %clang -DINLINE="__attribute__((noinline))" -target x86_64-linux-gnu \ // RUN: -O0 -o - -c -std=c99 -xc %s | llvm-nm - 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-NOINLINE %s -// RUN: %clang -DINLINE="static" -target x86_64-unknown-linux-gnu -o - \ -// RUN: -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -std=c99 -xc %s | \ +// RUN: %clang -c -DINLINE="static" -target x86_64-unknown-linux-gnu -o - \ +// RUN: -emit-interface-stubs -std=c99 -xc %s | \ // RUN: FileCheck -check-prefix=CHECK-STATIC %s // RUN: %clang -DINLINE="static" -target x86_64-linux-gnu -O0 -o - -c \ // RUN: -std=c99 -xc %s | llvm-nm - 2>&1 | \ @@ -50,12 +45,12 @@ return var; } -// RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -o - \ -// RUN: -emit-interface-stubs -interface-stub-version=experimental-ifs-v1 \ +// RUN: %clang -c -DINLINE=inline -target x86_64-linux-gnu -o - \ +// RUN: -emit-interface-stubs \ // RUN: -std=gnu89 -xc %s | FileCheck -check-prefix=CHECK-TAPI %s -// RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -o - \ -// RUN: -emit-interface-stubs -interface-stub-version=experimental-ifs-v1 \ +// RUN: %clang -c -DINLINE=inline -target x86_64-linux-gnu -o - \ +// RUN: -emit-interface-stubs \ // RUN: -std=gnu89 -xc %s | FileCheck -check-prefix=CHECK-SYMBOLS %s // RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -o - \ // RUN: -c -std=gnu89 -xc %s | llvm-nm - 2>&1 | \ Index: clang/test/InterfaceStubs/function-template-specialization.cpp =================================================================== --- clang/test/InterfaceStubs/function-template-specialization.cpp +++ clang/test/InterfaceStubs/function-template-specialization.cpp @@ -1,13 +1,15 @@ // REQUIRES: x86-registered-target -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ + +// TODO: Fix the case in llvm-ifs where it crashes on an empty Symbols list. +// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -c \ // RUN: -interface-stub-version=experimental-ifs-v1 %s | FileCheck %s -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ +// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -emit-merged-ifs \ // RUN: -interface-stub-version=experimental-ifs-v1 \ // RUN: -DUSE_TEMPLATE_FUNCTION=1 %s | \ // RUN: FileCheck -check-prefix=CHECK-USES-TEMPLATE-FUNCTION %s -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ +// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -emit-merged-ifs \ // RUN: -interface-stub-version=experimental-ifs-v1 \ // RUN: -DSPECIALIZE_TEMPLATE_FUNCTION=1 %s | \ // RUN: FileCheck -check-prefix=CHECK-SPECIALIZES-TEMPLATE-FUNCTION %s Index: clang/test/InterfaceStubs/func.ifs =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/func.ifs @@ -0,0 +1,40 @@ +# RUN: %clang -emit-interface-stubs -o - %s %S/object.ifs -emit-merged-ifs | \ +# RUN: FileCheck %s --check-prefixes=CHECK-IFS + +# RUN: %clang -emit-interface-stubs -o - %s %S/object.ifs | llvm-readelf --all | \ +# RUN: FileCheck %s --check-prefixes=CHECK-ELF + +# RUN: %clang -emit-interface-stubs -o - %s %s -emit-merged-ifs | \ +# RUN: FileCheck %s --check-prefixes=CHECK-MERGE-IFS + +# CHECK-IFS: --- !experimental-ifs-v1 +# CHECK-IFS-NEXT: IfsVersion: 1.0 +# CHECK-IFS-NEXT: Triple: x86_64-linux-gnu +# CHECK-IFS-NEXT: ObjectFileFormat: ELF +# CHECK-IFS-NEXT: Symbols: +# CHECK-IFS-DAG: a: { Type: Func } +# CHECK-IFS-DAG: b: { Type: Object, Size: 4 } +# CHECK-IFS: ... + +# CHECK-ELF: ELF Header: +# CHECK-ELF: Class: ELF64 +# CHECK-ELF: Type: DYN (Shared object file) +# CHECK-ELF: FUNC GLOBAL DEFAULT 1 a +# CHECK-ELF: OBJECT GLOBAL DEFAULT 1 b + +# Here we are testing to see if two identical symbols will merge. +# CHECK-MERGE-IFS: --- !experimental-ifs-v1 +# CHECK-MERGE-IFS-NEXT: IfsVersion: 1.0 +# CHECK-MERGE-IFS-NEXT: Triple: x86_64-linux-gnu +# CHECK-MERGE-IFS-NEXT: ObjectFileFormat: ELF +# CHECK-MERGE-IFS-NEXT: Symbols: +# CHECK-MERGE-IFS-NEXT: a: { Type: Func } +# CHECK-MERGE-IFS-NEXT: ... + +--- !experimental-ifs-v1 +IfsVersion: 1.0 +Triple: x86_64-linux-gnu +ObjectFileFormat: ELF +Symbols: + a: { Type: Func } +... Index: clang/test/InterfaceStubs/externstatic.c =================================================================== --- clang/test/InterfaceStubs/externstatic.c +++ clang/test/InterfaceStubs/externstatic.c @@ -1,24 +1,20 @@ -// REQUIRES: x86-registered-target -// RUN: %clang -DSTORAGE="extern" -target x86_64-unknown-linux-gnu -o - \ -// RUN: -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -std=c99 -xc %s | \ +// RUN: %clang -c -DSTORAGE="extern" -o - -emit-interface-stubs -std=c99 -xc %s | \ // RUN: FileCheck -check-prefix=CHECK-EXTERN %s -// RUN: %clang -DSTORAGE="extern" -target x86_64-linux-gnu -O0 -o - -c -std=c99 \ + +// RUN: %clang -DSTORAGE="extern" -O0 -o - -c -std=c99 \ // RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-EXTERN %s -// RUN: %clang -DSTORAGE="extern" -target x86_64-unknown-linux-gnu -o - \ -// RUN: -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -std=c99 -xc %s | \ +// RUN: %clang -c -DSTORAGE="extern" -o - -emit-interface-stubs -std=c99 -xc %s | \ +// RUN: FileCheck -check-prefix=CHECK-EXTERN2 %s + +// RUN: %clang -DSTORAGE="extern" -O0 -o - -c -std=c99 -xc %s | llvm-nm - 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-EXTERN2 %s -// RUN: %clang -DSTORAGE="extern" -target x86_64-linux-gnu -O0 -o - -c -std=c99 \ -// RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-EXTERN2 %s -// RUN: %clang -DSTORAGE="static" -target x86_64-unknown-linux-gnu -o - \ -// RUN: -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-ifs-v1 -std=c99 -xc %s | \ +// RUN: %clang -c -DSTORAGE="static" -o - -emit-interface-stubs -std=c99 -xc %s | \ +// RUN: FileCheck -check-prefix=CHECK-STATIC %s + +// RUN: %clang -DSTORAGE="static" -O0 -o - -c -std=c99 -xc %s | llvm-nm - 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-STATIC %s -// RUN: %clang -DSTORAGE="static" -target x86_64-linux-gnu -O0 -o - -c -std=c99 \ -// RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-STATIC %s // CHECK-EXTERN-NOT: foo // CHECK-STATIC-NOT: foo Index: clang/test/InterfaceStubs/driver-test.c =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/driver-test.c @@ -0,0 +1,12 @@ +// RUN: %clang -x c -o libfoo.so -emit-interface-stubs %s %S/object.c %S/weak.cpp && \ +// RUN: llvm-nm libfoo.so 2>&1 | FileCheck %s + +// RUN: %clang -x c -o libfoo.so -shared %s %S/object.c %S/weak.cpp && \ +// RUN: llvm-nm libfoo.so 2>&1 | FileCheck %s + +// CHECK-DAG: data +// CHECK-DAG: foo +// CHECK-DAG: strongFunc +// CHECK-DAG: weakFunc + +int foo(int bar) { return 42 + 1844; } \ No newline at end of file Index: clang/test/InterfaceStubs/conflict-type.ifs =================================================================== --- /dev/null +++ clang/test/InterfaceStubs/conflict-type.ifs @@ -0,0 +1,16 @@ +# RUN: not %clang -emit-merged-ifs -emit-interface-stubs -o - %s %S/func.ifs 2>&1 | \ +# RUN: FileCheck %s --check-prefixes=CHECK-IFS + +# Here we are testing to see if two symbols with identical names will fail to +# merge in conflict due to mismatched types. +# CHECK-IFS: error: Interface Stub: Type Mismatch for a. +# CHECK-IFS-NEXT: Filename: +# CHECK-IFS-NEXT: Type Values: Object Func + +--- !experimental-ifs-v1 +IfsVersion: 1.0 +Triple: x86_64-linux-gnu +ObjectFileFormat: ELF +Symbols: + a: { Type: Object, Size: 1 } +... Index: clang/test/InterfaceStubs/class-template-specialization.cpp =================================================================== --- clang/test/InterfaceStubs/class-template-specialization.cpp +++ clang/test/InterfaceStubs/class-template-specialization.cpp @@ -1,9 +1,9 @@ // REQUIRES: x86-registered-target -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ +// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -emit-merged-ifs \ // RUN: -interface-stub-version=experimental-ifs-v1 %s | \ // RUN: FileCheck -check-prefix=CHECK-TAPI %s -// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \ +// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -emit-merged-ifs \ // RUN: -interface-stub-version=experimental-ifs-v1 %s | \ // RUN: FileCheck -check-prefix=CHECK-TAPI2 %s // RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \ Index: clang/test/InterfaceStubs/bad-format.cpp =================================================================== --- clang/test/InterfaceStubs/bad-format.cpp +++ clang/test/InterfaceStubs/bad-format.cpp @@ -1,28 +1,25 @@ -// REQUIRES: x86-registered-target -// RUN: not %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=bar-format %s 2>&1 | FileCheck %s +// RUN: not %clang -emit-interface-stubs -interface-stub-version=bad-format %s 2>&1 | \ +// RUN: FileCheck %s -// RUN: not %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s 2>&1 | \ +// RUN: not %clang -emit-interface-stubs -interface-stub-version=experimental-tapi-elf-v1 %s 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-TAPI-DEPRECATED %s -// RUN: not %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s 2>&1 | \ +// RUN: not %clang -emit-interface-stubs -interface-stub-version=experimental-yaml-elf-v1 %s 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-YAML-DEPRECATED %s -// RUN: not %clang_cc1 -target x86_64-linux-gnu -o - -emit-interface-stubs \ -// RUN: -interface-stub-version=bar-format %s 2>&1 | FileCheck %s +// RUN: not %clang -emit-interface-stubs -interface-stub-version=bad-format %s 2>&1 | \ +// RUN: FileCheck %s -// RUN: not %clang_cc1 -target x86_64-linux-gnu -o - -emit-interface-stubs \ +// RUN: not %clang -emit-interface-stubs \ // RUN: -interface-stub-version=experimental-tapi-elf-v1 %s 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-TAPI-DEPRECATED %s -// RUN: not %clang_cc1 -target x86_64-linux-gnu -o - -emit-interface-stubs \ +// RUN: not %clang -emit-interface-stubs \ // RUN: -interface-stub-version=experimental-yaml-elf-v1 %s 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-YAML-DEPRECATED %s // CHECK: error: invalid value -// CHECK: 'Invalid interface stub format: bar-format.' in 'Must specify a +// CHECK: 'Invalid interface stub format: bad-format.' in 'Must specify a // CHECK: valid interface stub format type, ie: // CHECK: -interface-stub-version=experimental-ifs-v1' Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1734,24 +1734,25 @@ StringRef ArgStr = Args.hasArg(OPT_iterface_stub_version_EQ) ? Args.getLastArgValue(OPT_iterface_stub_version_EQ) - : ""; - llvm::Optional<frontend::ActionKind> ProgramAction = - llvm::StringSwitch<llvm::Optional<frontend::ActionKind>>(ArgStr) - .Case("experimental-ifs-v1", frontend::GenerateInterfaceIfsExpV1) - .Default(llvm::None); - if (!ProgramAction) { + : "experimental-ifs-v1"; + if (ArgStr == "experimental-yaml-elf-v1" || + ArgStr == "experimental-tapi-elf-v1") { std::string ErrorMessage = "Invalid interface stub format: " + ArgStr.str() + - ((ArgStr == "experimental-yaml-elf-v1" || - ArgStr == "experimental-tapi-elf-v1") - ? " is deprecated." - : "."); + " is deprecated."; + Diags.Report(diag::err_drv_invalid_value) + << "Must specify a valid interface stub format type, ie: " + "-interface-stub-version=experimental-ifs-v1" + << ErrorMessage; + } else if (ArgStr != "experimental-ifs-v1") { + std::string ErrorMessage = + "Invalid interface stub format: " + ArgStr.str() + "."; Diags.Report(diag::err_drv_invalid_value) << "Must specify a valid interface stub format type, ie: " "-interface-stub-version=experimental-ifs-v1" << ErrorMessage; } else { - Opts.ProgramAction = *ProgramAction; + Opts.ProgramAction = frontend::GenerateInterfaceIfsExpV1; } break; } Index: clang/lib/Driver/Types.cpp =================================================================== --- clang/lib/Driver/Types.cpp +++ clang/lib/Driver/Types.cpp @@ -269,6 +269,7 @@ .Case("lib", TY_Object) .Case("mii", TY_PP_ObjCXX) .Case("obj", TY_Object) + .Case("ifs", TY_IFS) .Case("pch", TY_PCH) .Case("pcm", TY_ModuleFile) .Case("c++m", TY_CXXModule) @@ -319,6 +320,22 @@ llvm::copy_if(PhaseList, std::back_inserter(P), [](phases::ID Phase) { return Phase <= phases::Precompile; }); + // Treat Interface Stubs like its own compilation mode. + else if (DAL.getLastArg(options::OPT_emit_iterface_stubs)) { + llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> IfsModePhaseList; + llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> &PL = PhaseList; + phases::ID LastPhase = phases::IfsMerge; + if (Id != types::TY_IFS) { + if (DAL.hasArg(options::OPT_c)) + LastPhase = phases::Compile; + PL = IfsModePhaseList; + types::getCompilationPhases(types::TY_IFS_CPP, PL); + } + llvm::copy_if(PL, std::back_inserter(P), [&](phases::ID Phase) { + return Phase <= LastPhase; + }); + } + // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler. else if (DAL.getLastArg(options::OPT_fsyntax_only) || DAL.getLastArg(options::OPT_print_supported_cpus) || @@ -327,7 +344,6 @@ DAL.getLastArg(options::OPT_rewrite_objc) || DAL.getLastArg(options::OPT_rewrite_legacy_objc) || DAL.getLastArg(options::OPT__migrate) || - DAL.getLastArg(options::OPT_emit_iterface_stubs) || DAL.getLastArg(options::OPT__analyze) || DAL.getLastArg(options::OPT_emit_ast)) llvm::copy_if(PhaseList, std::back_inserter(P), Index: clang/lib/Driver/ToolChains/InterfaceStubs.h =================================================================== --- /dev/null +++ clang/lib/Driver/ToolChains/InterfaceStubs.h @@ -0,0 +1,39 @@ +//===--- InterfaceStubs.cpp - Base InterfaceStubs Implementations C++ ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_IFS_H +#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_IFS_H + +#include "clang/Driver/Tool.h" +#include "clang/Driver/ToolChain.h" + +using namespace clang; +using namespace llvm::opt; + +namespace clang { +namespace driver { +namespace tools { +namespace ifstool { +class LLVM_LIBRARY_VISIBILITY Merger : public Tool { +public: + Merger(const ToolChain &TC) : Tool("IFS::Merger", "llvm-ifs", TC) {} + + bool hasIntegratedCPP() const override { return false; } + bool isLinkJob() const override { return false; } + + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; +}; +} // end namespace ifstool +} // end namespace tools +} // end namespace driver +} // end namespace clang + +#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_IFS_H Index: clang/lib/Driver/ToolChains/InterfaceStubs.cpp =================================================================== --- /dev/null +++ clang/lib/Driver/ToolChains/InterfaceStubs.cpp @@ -0,0 +1,37 @@ +//===--- InterfaceStubs.cpp - Base InterfaceStubs Implementations C++ ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "InterfaceStubs.h" +#include "CommonArgs.h" +#include "clang/Driver/Compilation.h" + +namespace clang { +namespace driver { +namespace tools { +namespace ifstool { +void Merger::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + std::string Merger = getToolChain().GetProgramPath(getShortName()); + ArgStringList CmdArgs; + CmdArgs.push_back("-action"); + CmdArgs.push_back(Args.getLastArg(options::OPT_emit_merged_ifs) + ? "write-ifs" + : "write-bin"); + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + for (const auto &Input : Inputs) + CmdArgs.push_back(Input.getFilename()); + C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Merger), + CmdArgs, Inputs)); +} +} // namespace ifstool +} // namespace tools +} // namespace driver +} // namespace clang Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -3673,32 +3673,15 @@ } else if (JA.getType() == types::TY_LLVM_BC || JA.getType() == types::TY_LTO_BC) { CmdArgs.push_back("-emit-llvm-bc"); - } else if (JA.getType() == types::TY_IFS) { + } else if (JA.getType() == types::TY_IFS || + JA.getType() == types::TY_IFS_CPP) { StringRef ArgStr = Args.hasArg(options::OPT_iterface_stub_version_EQ) ? Args.getLastArgValue(options::OPT_iterface_stub_version_EQ) - : ""; - StringRef StubFormat = - llvm::StringSwitch<StringRef>(ArgStr) - .Case("experimental-ifs-v1", "experimental-ifs-v1") - .Default(""); - - if (StubFormat.empty()) { - std::string ErrorMessage = - "Invalid interface stub format: " + ArgStr.str() + - ((ArgStr == "experimental-yaml-elf-v1" || - ArgStr == "experimental-tapi-elf-v1") - ? " is deprecated." - : "."); - D.Diag(diag::err_drv_invalid_value) - << "Must specify a valid interface stub format type, ie: " - "-interface-stub-version=experimental-ifs-v1" - << ErrorMessage; - } - + : "experimental-ifs-v1"; CmdArgs.push_back("-emit-interface-stubs"); CmdArgs.push_back( - Args.MakeArgString(Twine("-interface-stub-version=") + StubFormat)); + Args.MakeArgString(Twine("-interface-stub-version=") + ArgStr.str())); } else if (JA.getType() == types::TY_PP_Asm) { CmdArgs.push_back("-S"); } else if (JA.getType() == types::TY_AST) { Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -10,6 +10,7 @@ #include "InputInfo.h" #include "ToolChains/Arch/ARM.h" #include "ToolChains/Clang.h" +#include "ToolChains/InterfaceStubs.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Sanitizers.h" #include "clang/Config/config.h" @@ -279,6 +280,12 @@ return Link.get(); } +Tool *ToolChain::getIfsMerge() const { + if (!IfsMerge) + IfsMerge.reset(new tools::ifstool::Merger(*this)); + return IfsMerge.get(); +} + Tool *ToolChain::getOffloadBundler() const { if (!OffloadBundler) OffloadBundler.reset(new tools::OffloadBundler(*this)); @@ -290,6 +297,9 @@ case Action::AssembleJobClass: return getAssemble(); + case Action::IfsMergeJobClass: + return getIfsMerge(); + case Action::LinkJobClass: return getLink(); Index: clang/lib/Driver/Phases.cpp =================================================================== --- clang/lib/Driver/Phases.cpp +++ clang/lib/Driver/Phases.cpp @@ -20,6 +20,7 @@ case Backend: return "backend"; case Assemble: return "assembler"; case Link: return "linker"; + case IfsMerge: return "ifsmerger"; } llvm_unreachable("Invalid phase id."); Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -274,11 +274,11 @@ (PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) { FinalPhase = phases::Preprocess; - // --precompile only runs up to precompilation. + // --precompile only runs up to precompilation. } else if ((PhaseArg = DAL.getLastArg(options::OPT__precompile))) { FinalPhase = phases::Precompile; - // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler. + // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler. } else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) || (PhaseArg = DAL.getLastArg(options::OPT_print_supported_cpus)) || (PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) || @@ -286,20 +286,23 @@ (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) || (PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) || (PhaseArg = DAL.getLastArg(options::OPT__migrate)) || - (PhaseArg = DAL.getLastArg(options::OPT_emit_iterface_stubs)) || (PhaseArg = DAL.getLastArg(options::OPT__analyze)) || (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) { FinalPhase = phases::Compile; - // -S only runs up to the backend. + // clang interface stubs + } else if ((PhaseArg = DAL.getLastArg(options::OPT_emit_iterface_stubs))) { + FinalPhase = phases::IfsMerge; + + // -S only runs up to the backend. } else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) { FinalPhase = phases::Backend; - // -c compilation only runs up to the assembler. + // -c compilation only runs up to the assembler. } else if ((PhaseArg = DAL.getLastArg(options::OPT_c))) { FinalPhase = phases::Assemble; - // Otherwise do everything. + // Otherwise do everything. } else FinalPhase = phases::Link; @@ -3325,6 +3328,7 @@ // Construct the actions to perform. HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr; ActionList LinkerInputs; + ActionList MergerInputs; for (auto &I : Inputs) { types::ID InputType = I.first; @@ -3362,6 +3366,14 @@ break; } + // Queue merger inputs. + if (Phase == phases::IfsMerge) { + assert(Phase == PL.back() && "merging must be final compilation step."); + MergerInputs.push_back(Current); + Current = nullptr; + break; + } + // Each precompiled header file after a module file action is a module // header of that same module file, rather than being compiled to a // separate PCH. @@ -3411,6 +3423,11 @@ Actions.push_back(LA); } + // Add an interface stubs merge action if necessary. + if (!MergerInputs.empty()) + Actions.push_back( + C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image)); + // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a custom // Compile phase that prints out supported cpu models and quits. if (Arg *A = Args.getLastArg(options::OPT_print_supported_cpus)) { @@ -3447,6 +3464,8 @@ switch (Phase) { case phases::Link: llvm_unreachable("link action invalid here."); + case phases::IfsMerge: + llvm_unreachable("ifsmerge action invalid here."); case phases::Preprocess: { types::ID OutputTy; // -M and -MM specify the dependency file name by altering the output type, @@ -3511,7 +3530,7 @@ if (Args.hasArg(options::OPT_verify_pch)) return C.MakeAction<VerifyPCHJobAction>(Input, types::TY_Nothing); if (Args.hasArg(options::OPT_emit_iterface_stubs)) - return C.MakeAction<CompileJobAction>(Input, types::TY_IFS); + return C.MakeAction<CompileJobAction>(Input, types::TY_IFS_CPP); return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC); } case phases::Backend: { Index: clang/lib/Driver/CMakeLists.txt =================================================================== --- clang/lib/Driver/CMakeLists.txt +++ clang/lib/Driver/CMakeLists.txt @@ -66,6 +66,7 @@ ToolChains/WebAssembly.cpp ToolChains/XCore.cpp ToolChains/PPCLinux.cpp + ToolChains/InterfaceStubs.cpp Types.cpp XRayArgs.cpp Index: clang/lib/Driver/Action.cpp =================================================================== --- clang/lib/Driver/Action.cpp +++ clang/lib/Driver/Action.cpp @@ -31,6 +31,7 @@ case CompileJobClass: return "compiler"; case BackendJobClass: return "backend"; case AssembleJobClass: return "assembler"; + case IfsMergeJobClass: return "interface-stub-merger"; case LinkJobClass: return "linker"; case LipoJobClass: return "lipo"; case DsymutilJobClass: return "dsymutil"; @@ -357,6 +358,11 @@ AssembleJobAction::AssembleJobAction(Action *Input, types::ID OutputType) : JobAction(AssembleJobClass, Input, OutputType) {} +void IfsMergeJobAction::anchor() {} + +IfsMergeJobAction::IfsMergeJobAction(ActionList &Inputs, types::ID Type) + : JobAction(IfsMergeJobClass, Inputs, Type) {} + void LinkJobAction::anchor() {} LinkJobAction::LinkJobAction(ActionList &Inputs, types::ID Type) Index: clang/include/clang/Driver/Types.def =================================================================== --- clang/include/clang/Driver/Types.def +++ clang/include/clang/Driver/Types.def @@ -84,7 +84,8 @@ // Misc. TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link) -TYPE("ifs", IFS, INVALID, "ifs", phases::Compile, phases::Backend, phases::Assemble, phases::Link) +TYPE("ifs", IFS, INVALID, "ifs", phases::IfsMerge) +TYPE("ifs-cpp", IFS_CPP, INVALID, "ifs", phases::Compile, phases::IfsMerge) TYPE("pcm", ModuleFile, INVALID, "pcm", phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("plist", Plist, INVALID, "plist", phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("rewritten-objc", RewrittenObjC,INVALID, "cpp", phases::Compile, phases::Backend, phases::Assemble, phases::Link) Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -136,11 +136,13 @@ mutable std::unique_ptr<Tool> Clang; mutable std::unique_ptr<Tool> Assemble; mutable std::unique_ptr<Tool> Link; + mutable std::unique_ptr<Tool> IfsMerge; mutable std::unique_ptr<Tool> OffloadBundler; Tool *getClang() const; Tool *getAssemble() const; Tool *getLink() const; + Tool *getIfsMerge() const; Tool *getClangAs() const; Tool *getOffloadBundler() const; Index: clang/include/clang/Driver/Phases.h =================================================================== --- clang/include/clang/Driver/Phases.h +++ clang/include/clang/Driver/Phases.h @@ -20,7 +20,8 @@ Compile, Backend, Assemble, - Link + Link, + IfsMerge, }; enum { Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -633,6 +633,9 @@ HelpText<"Use the LLVM representation for assembler and object files">; def emit_iterface_stubs : Flag<["-"], "emit-interface-stubs">, Flags<[CC1Option]>, Group<Action_Group>, HelpText<"Generate Inteface Stub Files.">; +def emit_merged_ifs : Flag<["-"], "emit-merged-ifs">, + Flags<[CC1Option]>, Group<Action_Group>, + HelpText<"Generate Interface Stub Files, emit merged text not binary.">; def iterface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Flags<[CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; def e : JoinedOrSeparate<["-"], "e">, Group<Link_Group>; Index: clang/include/clang/Driver/Action.h =================================================================== --- clang/include/clang/Driver/Action.h +++ clang/include/clang/Driver/Action.h @@ -65,6 +65,7 @@ BackendJobClass, AssembleJobClass, LinkJobClass, + IfsMergeJobClass, LipoJobClass, DsymutilJobClass, VerifyDebugInfoJobClass, @@ -485,6 +486,17 @@ } }; +class IfsMergeJobAction : public JobAction { + void anchor() override; + +public: + IfsMergeJobAction(ActionList &Inputs, types::ID Type); + + static bool classof(const Action *A) { + return A->getKind() == IfsMergeJobClass; + } +}; + class LinkJobAction : public JobAction { void anchor() override;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits