[PATCH] D71493: [WebAssembly] Setting export_name implies no_dead_strip
Sam Clegg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 13 14:50:53 PST 2019
sbc100 created this revision.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, aheejin, hiraditya, jgravelle-google, dschuff.
Herald added projects: clang, LLVM.
sbc100 added reviewers: dschuff, sunfish.
This change updates the clang front end to add symbols to llvm.used
when they have explicit export_name attribute.
In also causes the `.export_name` assempler directive to imply the
MCSA_NoDeadStrip symbol attribute.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71493
Files:
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/wasm-export-name.c
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/test/MC/WebAssembly/export-name.s
Index: llvm/test/MC/WebAssembly/export-name.s
===================================================================
--- llvm/test/MC/WebAssembly/export-name.s
+++ llvm/test/MC/WebAssembly/export-name.s
@@ -22,5 +22,5 @@
# CHECK-OBJ-NEXT: - Index: 0
# CHECK-OBJ-NEXT: Kind: FUNCTION
# CHECK-OBJ-NEXT: Name: foo
-# CHECK-OBJ-NEXT: Flags: [ EXPORTED ]
+# CHECK-OBJ-NEXT: Flags: [ EXPORTED, NO_STRIP ]
# CHECK-OBJ-NEXT: Function: 0
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -722,6 +722,7 @@
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
WasmSym->setExportName(ExportName);
TOut.emitExportName(WasmSym, ExportName);
+ Out.EmitSymbolAttribute(WasmSym, MCSA_NoDeadStrip);
}
if (DirectiveID.getString() == ".import_module") {
Index: clang/test/CodeGen/wasm-export-name.c
===================================================================
--- clang/test/CodeGen/wasm-export-name.c
+++ clang/test/CodeGen/wasm-export-name.c
@@ -6,6 +6,8 @@
return 43;
}
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @foo to i8*)]
+
// CHECK: define i32 @foo() [[A:#[0-9]+]]
// CHECK: attributes [[A]] = {{{.*}} "wasm-export-name"="bar" {{.*}}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5772,8 +5772,8 @@
if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc))
return;
- FD->addAttr(::new (S.Context)
- WebAssemblyExportNameAttr(S.Context, AL, Str));
+ D->addAttr(::new (S.Context) WebAssemblyExportNameAttr(S.Context, AL, Str));
+ D->addAttr(UsedAttr::CreateImplicit(S.Context));
}
static void handleWebAssemblyImportModuleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71493.233886.patch
Type: text/x-patch
Size: 2159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191213/fc28f726/attachment.bin>
More information about the cfe-commits
mailing list