diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-06-14 16:58:26 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-06-14 16:58:26 -0700 |
commit | 263d9c76d6975df0a864396919c326063380f75e (patch) | |
tree | 2833f0f249ec438391f1d0e282470e8e9f16e5fc | |
parent | c31b941a4fc4c995cbc40d5f4be6705d61eda011 (diff) |
PNaCl ABI: Convert "private" linkage to "internal"
This simplifies the ABI by reducing the number of linkage types we
have to check for and represent in the wire format.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3495
TEST=*.ll tests + PNaCl toolchain trybots
Review URL: https://codereview.chromium.org/17084003
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyModule.cpp | 1 | ||||
-rw-r--r-- | lib/Transforms/NaCl/StripAttributes.cpp | 21 | ||||
-rw-r--r-- | test/NaCl/PNaClABI/linkagetypes.ll | 20 |
3 files changed, 30 insertions, 12 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp index baa072f390..c0a5e4bcc2 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp @@ -110,7 +110,6 @@ void PNaClABIVerifyModule::checkGlobalValueCommon(const GlobalValue *GV) { case GlobalValue::ExternalLinkage: case GlobalValue::AvailableExternallyLinkage: case GlobalValue::InternalLinkage: - case GlobalValue::PrivateLinkage: break; default: Reporter->addError() << GVTypeName << GV->getName() diff --git a/lib/Transforms/NaCl/StripAttributes.cpp b/lib/Transforms/NaCl/StripAttributes.cpp index a28aee3ad1..5c2ff72daa 100644 --- a/lib/Transforms/NaCl/StripAttributes.cpp +++ b/lib/Transforms/NaCl/StripAttributes.cpp @@ -135,12 +135,25 @@ static void CheckAttributes(AttributeSet Attrs) { } } +void stripGlobalValueAttrs(GlobalValue *GV) { + GV->setUnnamedAddr(false); + + // Convert "private" linkage to "internal" to reduce the number of + // linkage types that need to be represented in PNaCl's wire format. + // + // We convert "private" to "internal" rather than vice versa because + // "private" symbols are omitted from the nexe's symbol table, which + // would get in the way of debugging when an unstripped pexe is + // translated offline. + if (GV->getLinkage() == GlobalValue::PrivateLinkage) + GV->setLinkage(GlobalValue::InternalLinkage); +} + void stripFunctionAttrs(Function *Func) { CheckAttributes(Func->getAttributes()); Func->setAttributes(AttributeSet()); Func->setCallingConv(CallingConv::C); Func->setAlignment(0); - Func->setUnnamedAddr(false); for (Function::iterator BB = Func->begin(), E = Func->end(); BB != E; ++BB) { @@ -169,12 +182,14 @@ bool StripAttributes::runOnModule(Module &M) { // constructor for Functions just adds them back again. It would // be confusing if the attributes were sometimes present on // intrinsics and sometimes not. - if (!Func->isIntrinsic()) + if (!Func->isIntrinsic()) { + stripGlobalValueAttrs(Func); stripFunctionAttrs(Func); + } } for (Module::global_iterator GV = M.global_begin(), E = M.global_end(); GV != E; ++GV) { - GV->setUnnamedAddr(false); + stripGlobalValueAttrs(GV); } return true; } diff --git a/test/NaCl/PNaClABI/linkagetypes.ll b/test/NaCl/PNaClABI/linkagetypes.ll index f19ed48796..61a5286838 100644 --- a/test/NaCl/PNaClABI/linkagetypes.ll +++ b/test/NaCl/PNaClABI/linkagetypes.ll @@ -5,15 +5,16 @@ target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64 target triple = "le32-unknown-nacl" +@gv_internal = internal global [1 x i8] c"x" +; CHECK-NOT: disallowed + @gv_private = private global [1 x i8] c"x" +; CHECK: Variable gv_private has disallowed linkage type: private @gv_linker_private = linker_private global [1 x i8] c"x" -; CHECK-NOT: disallowed ; CHECK: Variable gv_linker_private has disallowed linkage type: linker_private @gv_linker_private_weak = linker_private_weak global [1 x i8] c"x" ; CHECK: gv_linker_private_weak has disallowed linkage type: linker_private_weak -@gv_internal = internal global [1 x i8] c"x" @gv_linkonce = linkonce global [1 x i8] c"x" -; CHECK-NOT: disallowed ; CHECK: gv_linkonce has disallowed linkage type: linkonce @gv_linkonce_odr = linkonce_odr global [1 x i8] c"x" ; CHECK: gv_linkonce_odr has disallowed linkage type: linkonce_odr @@ -35,15 +36,18 @@ target triple = "le32-unknown-nacl" ; CHECK: gv_extern_weak has disallowed linkage type: extern_weak @gv_avilable_externally = available_externally global [1 x i8] c"x" -; CHECK-NOT: private_func -define private void @private_func() { - ret void -} -; internal linkage is allowed, and should not appear in error output. + +; CHECK-NOT: disallowed ; CHECK-NOT: internal_func +; internal linkage is allowed, and should not appear in error output. define internal void @internal_func() { ret void } + +; CHECK: Function private_func has disallowed linkage type: private +define private void @private_func() { + ret void +} ; CHECK: Function external_func is declared but not defined (disallowed) declare external void @external_func() ; CHECK: linkonce_func has disallowed linkage type: linkonce |