Skip to content

Commit e3033c0

Browse files
committed
[llvm][clang][IFS] Enhancing the llvm-ifs yaml format for symbol lists.
Prior to this change the clang interface stubs format resembled something ending with a symbol list like this: Symbols: a: { Type: Func } This was problematic because we didn't actually want a map format and also because we didn't like that an empty symbol list required "Symbols: {}". That is to say without the empty {} llvm-ifs would crash on an empty list. With this new format it is much more clear which field is the symbol name, and instead the [] that is used to express an empty symbol vector is optional, ie: Symbols: - { Name: a, Type: Func } or Symbols: [] or Symbols: This further diverges the format from existing llvm-elftapi. This is a good thing because although the format originally came from the same place, they are not the same in any way. Differential Revision: https://reviews.llvm.org/D76979
1 parent a67cd71 commit e3033c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+265
-227
lines changed

clang/include/clang/Frontend/FrontendActions.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,13 @@ class GenerateModuleAction : public ASTFrontendAction {
119119
bool hasASTFileSupport() const override { return false; }
120120
};
121121

122-
class GenerateInterfaceStubAction : public ASTFrontendAction {
123-
protected:
124-
TranslationUnitKind getTranslationUnitKind() override { return TU_Module; }
125-
126-
bool hasASTFileSupport() const override { return false; }
127-
};
128-
129-
class GenerateInterfaceIfsExpV1Action : public GenerateInterfaceStubAction {
122+
class GenerateInterfaceStubsAction : public ASTFrontendAction {
130123
protected:
131124
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
132125
StringRef InFile) override;
126+
127+
TranslationUnitKind getTranslationUnitKind() override { return TU_Module; }
128+
bool hasASTFileSupport() const override { return false; }
133129
};
134130

135131
class GenerateModuleFromModuleMapAction : public GenerateModuleAction {

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ enum ActionKind {
9090
GeneratePCH,
9191

9292
/// Generate Interface Stub Files.
93-
GenerateInterfaceIfsExpV1,
93+
GenerateInterfaceStubs,
9494

9595
/// Only execute frontend initialization.
9696
InitOnly,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4184,7 +4184,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41844184
StringRef ArgStr =
41854185
Args.hasArg(options::OPT_interface_stub_version_EQ)
41864186
? Args.getLastArgValue(options::OPT_interface_stub_version_EQ)
4187-
: "experimental-ifs-v1";
4187+
: "experimental-ifs-v2";
41884188
CmdArgs.push_back("-emit-interface-stubs");
41894189
CmdArgs.push_back(
41904190
Args.MakeArgString(Twine("-interface-stub-version=") + ArgStr.str()));

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,25 +1780,26 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
17801780
StringRef ArgStr =
17811781
Args.hasArg(OPT_interface_stub_version_EQ)
17821782
? Args.getLastArgValue(OPT_interface_stub_version_EQ)
1783-
: "experimental-ifs-v1";
1783+
: "experimental-ifs-v2";
17841784
if (ArgStr == "experimental-yaml-elf-v1" ||
1785+
ArgStr == "experimental-ifs-v1" ||
17851786
ArgStr == "experimental-tapi-elf-v1") {
17861787
std::string ErrorMessage =
17871788
"Invalid interface stub format: " + ArgStr.str() +
17881789
" is deprecated.";
17891790
Diags.Report(diag::err_drv_invalid_value)
17901791
<< "Must specify a valid interface stub format type, ie: "
1791-
"-interface-stub-version=experimental-ifs-v1"
1792+
"-interface-stub-version=experimental-ifs-v2"
17921793
<< ErrorMessage;
1793-
} else if (ArgStr != "experimental-ifs-v1") {
1794+
} else if (!ArgStr.startswith("experimental-ifs-")) {
17941795
std::string ErrorMessage =
17951796
"Invalid interface stub format: " + ArgStr.str() + ".";
17961797
Diags.Report(diag::err_drv_invalid_value)
17971798
<< "Must specify a valid interface stub format type, ie: "
1798-
"-interface-stub-version=experimental-ifs-v1"
1799+
"-interface-stub-version=experimental-ifs-v2"
17991800
<< ErrorMessage;
18001801
} else {
1801-
Opts.ProgramAction = frontend::GenerateInterfaceIfsExpV1;
1802+
Opts.ProgramAction = frontend::GenerateInterfaceStubs;
18021803
}
18031804
break;
18041805
}
@@ -3367,7 +3368,7 @@ static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
33673368
case frontend::GenerateModuleInterface:
33683369
case frontend::GenerateHeaderModule:
33693370
case frontend::GeneratePCH:
3370-
case frontend::GenerateInterfaceIfsExpV1:
3371+
case frontend::GenerateInterfaceStubs:
33713372
case frontend::ParseSyntaxOnly:
33723373
case frontend::ModuleFileInfo:
33733374
case frontend::VerifyPCH:

clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
290290
const ASTContext &context, StringRef Format,
291291
raw_ostream &OS) -> void {
292292
OS << "--- !" << Format << "\n";
293-
OS << "IfsVersion: 1.0\n";
293+
OS << "IfsVersion: 2.0\n";
294294
OS << "Triple: " << T.str() << "\n";
295295
OS << "ObjectFileFormat: "
296296
<< "ELF"
@@ -299,11 +299,11 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
299299
for (const auto &E : Symbols) {
300300
const MangledSymbol &Symbol = E.second;
301301
for (auto Name : Symbol.Names) {
302-
OS << " \""
302+
OS << " - { Name: \""
303303
<< (Symbol.ParentName.empty() || Instance.getLangOpts().CPlusPlus
304304
? ""
305305
: (Symbol.ParentName + "."))
306-
<< Name << "\" : { Type: ";
306+
<< Name << "\", Type: ";
307307
switch (Symbol.Type) {
308308
default:
309309
llvm_unreachable(
@@ -330,15 +330,15 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
330330
OS.flush();
331331
};
332332

333-
assert(Format == "experimental-ifs-v1" && "Unexpected IFS Format.");
333+
assert(Format == "experimental-ifs-v2" && "Unexpected IFS Format.");
334334
writeIfsV1(Instance.getTarget().getTriple(), Symbols, context, Format, *OS);
335335
}
336336
};
337337
} // namespace
338338

339339
std::unique_ptr<ASTConsumer>
340-
GenerateInterfaceIfsExpV1Action::CreateASTConsumer(CompilerInstance &CI,
341-
StringRef InFile) {
340+
GenerateInterfaceStubsAction::CreateASTConsumer(CompilerInstance &CI,
341+
StringRef InFile) {
342342
return std::make_unique<InterfaceStubFunctionsConsumer>(
343-
CI, InFile, "experimental-ifs-v1");
343+
CI, InFile, "experimental-ifs-v2");
344344
}

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
6565
case GenerateHeaderModule:
6666
return std::make_unique<GenerateHeaderModuleAction>();
6767
case GeneratePCH: return std::make_unique<GeneratePCHAction>();
68-
case GenerateInterfaceIfsExpV1:
69-
return std::make_unique<GenerateInterfaceIfsExpV1Action>();
68+
case GenerateInterfaceStubs:
69+
return std::make_unique<GenerateInterfaceStubsAction>();
7070
case InitOnly: return std::make_unique<InitOnlyAction>();
7171
case ParseSyntaxOnly: return std::make_unique<SyntaxOnlyAction>();
7272
case ModuleFileInfo: return std::make_unique<DumpModuleInfoAction>();

clang/test/InterfaceStubs/bad-format.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// RUN: not %clang -emit-interface-stubs -interface-stub-version=experimental-yaml-elf-v1 %s 2>&1 | \
88
// RUN: FileCheck -check-prefix=CHECK-YAML-DEPRECATED %s
99

10+
// RUN: not %clang -emit-interface-stubs -interface-stub-version=experimental-ifs-v1 %s 2>&1 | \
11+
// RUN: FileCheck -check-prefix=CHECK-V1-DEPRECATED %s
12+
1013
// RUN: not %clang -emit-interface-stubs -interface-stub-version=bad-format %s 2>&1 | \
1114
// RUN: FileCheck %s
1215

@@ -21,16 +24,22 @@
2124
// CHECK: error: invalid value
2225
// CHECK: 'Invalid interface stub format: bad-format.' in 'Must specify a
2326
// CHECK: valid interface stub format type, ie:
24-
// CHECK: -interface-stub-version=experimental-ifs-v1'
27+
// CHECK: -interface-stub-version=experimental-ifs-v2'
2528

2629
// CHECK-TAPI-DEPRECATED: error: invalid value
2730
// CHECK-TAPI-DEPRECATED: 'Invalid interface stub format:
2831
// CHECK-TAPI-DEPRECATED: experimental-tapi-elf-v1 is deprecated.' in 'Must
2932
// CHECK-TAPI-DEPRECATED: specify a valid interface stub format type, ie:
30-
// CHECK-TAPI-DEPRECATED: -interface-stub-version=experimental-ifs-v1'
33+
// CHECK-TAPI-DEPRECATED: -interface-stub-version=experimental-ifs-v2'
3134

3235
// CHECK-YAML-DEPRECATED: error: invalid value
3336
// CHECK-YAML-DEPRECATED: 'Invalid interface stub format:
3437
// CHECK-YAML-DEPRECATED: experimental-yaml-elf-v1 is deprecated.' in 'Must
3538
// CHECK-YAML-DEPRECATED: specify a valid interface stub format type, ie:
36-
// CHECK-YAML-DEPRECATED: -interface-stub-version=experimental-ifs-v1'
39+
// CHECK-YAML-DEPRECATED: -interface-stub-version=experimental-ifs-v2'
40+
41+
// CHECK-V1-DEPRECATED: error: invalid value
42+
// CHECK-V1-DEPRECATED: 'Invalid interface stub format:
43+
// CHECK-V1-DEPRECATED: experimental-ifs-v1 is deprecated.' in 'Must
44+
// CHECK-V1-DEPRECATED: specify a valid interface stub format type, ie:
45+
// CHECK-V1-DEPRECATED: -interface-stub-version=experimental-ifs-v2'

clang/test/InterfaceStubs/blocks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cc1 -emit-interface-stubs -fblocks -o - %s | FileCheck %s
22

3-
// CHECK: --- !experimental-ifs-v1
4-
// CHECK-NEXT: IfsVersion: 1.0
3+
// CHECK: --- !experimental-ifs-v2
4+
// CHECK-NEXT: IfsVersion: 2.0
55
// CHECK-NEXT: Triple:
66
// CHECK-NEXT: ObjectFileFormat: ELF
77
// CHECK-NEXT: Symbols:

clang/test/InterfaceStubs/class-template-partial-specialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cc1 -o - -emit-interface-stubs %s | FileCheck %s
22

3-
// CHECK: --- !experimental-ifs-v1
4-
// CHECK-NEXT: IfsVersion: 1.0
3+
// CHECK: --- !experimental-ifs-v2
4+
// CHECK-NEXT: IfsVersion: 2.0
55
// CHECK-NEXT: Triple:
66
// CHECK-NEXT: ObjectFileFormat: ELF
77
// CHECK-NEXT: Symbols:

clang/test/InterfaceStubs/conflict-type.ifs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# CHECK-IFS-NEXT: Filename:
88
# CHECK-IFS-NEXT: Type Values: Object Func
99

10-
--- !experimental-ifs-v1
11-
IfsVersion: 1.0
10+
--- !experimental-ifs-v2
11+
IfsVersion: 2.0
1212
Triple: x86_64-linux-gnu
1313
ObjectFileFormat: ELF
1414
Symbols:
15-
a: { Type: Object, Size: 1 }
15+
- { Name: a, Type: Object, Size: 1 }
1616
...

0 commit comments

Comments
 (0)