diff options
author | Sam Clegg <sbc@chromium.org> | 2019-02-04 23:07:34 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2019-02-04 23:07:34 +0000 |
commit | 313f9f54f5a85790ae09cc48c1df54a4c635a3e3 (patch) | |
tree | 310e330d55647af41f5902b5d5e096b6266439b3 /llvm/lib/CodeGen | |
parent | 7c907bac6fd51835ed4410845cc25b44cdd08c95 (diff) | |
download | bcm5719-llvm-313f9f54f5a85790ae09cc48c1df54a4c635a3e3.tar.gz bcm5719-llvm-313f9f54f5a85790ae09cc48c1df54a4c635a3e3.zip |
[WebAssembly] MC: Mark more function aliases as functions
Aliases of functions are now marked as function symbols even if
they are bitcast to some other other non-function type.
This is important for WebAssembly where object and function
symbols can't alias each other.
Fixes PR38866
Differential Revision: https://reviews.llvm.org/D57538
llvm-svn: 353109
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index be666add18b..619f706ec62 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1286,9 +1286,19 @@ void AsmPrinter::emitGlobalIndirectSymbol(Module &M, else assert(GIS.hasLocalLinkage() && "Invalid alias or ifunc linkage"); + bool IsFunction = GIS.getType()->getPointerElementType()->isFunctionTy(); + + // Treat bitcasts of functions as functions also. This is important at least + // on WebAssembly where object and function addresses can't alias each other. + if (!IsFunction) + if (auto *CE = dyn_cast<ConstantExpr>(GIS.getIndirectSymbol())) + if (CE->getOpcode() == Instruction::BitCast) + IsFunction = + CE->getOperand(0)->getType()->getPointerElementType()->isFunctionTy(); + // Set the symbol type to function if the alias has a function type. // This affects codegen when the aliasee is not a function. - if (GIS.getType()->getPointerElementType()->isFunctionTy()) { + if (IsFunction) { OutStreamer->EmitSymbolAttribute(Name, MCSA_ELF_TypeFunction); if (isa<GlobalIFunc>(GIS)) OutStreamer->EmitSymbolAttribute(Name, MCSA_ELF_TypeIndFunction); |