aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2013-06-16 11:04:50 -0700
committerMark Seaborn <mseaborn@chromium.org>2013-06-16 11:04:50 -0700
commit36362aa384aa0fc2d6682978301178b52530550d (patch)
tree8807ecf7e6c835d7244bf130f6ecd4bf5e6b0603
parent8dd5d093f3f298dd140256c56248bb18e4ac8295 (diff)
PNaCl ABI: Disallow non-default symbol visibility ("hidden" and "protected")
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3495 TEST=*.ll tests + PNaCl toolchain trybots Review URL: https://codereview.chromium.org/16903003
-rw-r--r--lib/Analysis/NaCl/PNaClABIVerifyModule.cpp10
-rw-r--r--lib/Transforms/NaCl/StripAttributes.cpp4
-rw-r--r--test/NaCl/PNaClABI/abi-visibility.ll15
-rw-r--r--test/Transforms/NaCl/strip-attributes.ll10
4 files changed, 39 insertions, 0 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
index 2cc6572606..675b62a974 100644
--- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
+++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
@@ -115,6 +115,16 @@ void PNaClABIVerifyModule::checkGlobalValueCommon(const GlobalValue *GV) {
<< " has disallowed linkage type: "
<< linkageName(GV->getLinkage()) << "\n";
}
+ if (GV->getVisibility() != GlobalValue::DefaultVisibility) {
+ std::string Text = "unknown";
+ if (GV->getVisibility() == GlobalValue::HiddenVisibility) {
+ Text = "hidden";
+ } else if (GV->getVisibility() == GlobalValue::ProtectedVisibility) {
+ Text = "protected";
+ }
+ Reporter->addError() << GVTypeName << GV->getName()
+ << " has disallowed visibility: " << Text << "\n";
+ }
if (GV->hasSection()) {
Reporter->addError() << GVTypeName << GV->getName() <<
" has disallowed \"section\" attribute\n";
diff --git a/lib/Transforms/NaCl/StripAttributes.cpp b/lib/Transforms/NaCl/StripAttributes.cpp
index 5c2ff72daa..e1ce855679 100644
--- a/lib/Transforms/NaCl/StripAttributes.cpp
+++ b/lib/Transforms/NaCl/StripAttributes.cpp
@@ -136,6 +136,10 @@ static void CheckAttributes(AttributeSet Attrs) {
}
void stripGlobalValueAttrs(GlobalValue *GV) {
+ // In case source code uses __attribute__((visibility("hidden"))) or
+ // __attribute__((visibility("protected"))), strip these attributes.
+ GV->setVisibility(GlobalValue::DefaultVisibility);
+
GV->setUnnamedAddr(false);
// Convert "private" linkage to "internal" to reduce the number of
diff --git a/test/NaCl/PNaClABI/abi-visibility.ll b/test/NaCl/PNaClABI/abi-visibility.ll
new file mode 100644
index 0000000000..1c54b248b4
--- /dev/null
+++ b/test/NaCl/PNaClABI/abi-visibility.ll
@@ -0,0 +1,15 @@
+; RUN: pnacl-abicheck < %s | FileCheck %s
+
+; Disallow the visibility attributes set by
+; __attribute__((visibility("hidden"))) and
+; __attribute__((visibility("protected"))).
+
+define internal hidden void @visibility_hidden() {
+ ret void
+}
+; CHECK: Function visibility_hidden has disallowed visibility: hidden
+
+define internal protected void @visibility_protected() {
+ ret void
+}
+; CHECK-NEXT: Function visibility_protected has disallowed visibility: protected
diff --git a/test/Transforms/NaCl/strip-attributes.ll b/test/Transforms/NaCl/strip-attributes.ll
index f844e2dd88..8ef83f5cf8 100644
--- a/test/Transforms/NaCl/strip-attributes.ll
+++ b/test/Transforms/NaCl/strip-attributes.ll
@@ -11,6 +11,16 @@ define fastcc void @func_attrs(i32 inreg, i32 zeroext)
}
; CHECK: define void @func_attrs(i32, i32) {
+define hidden void @hidden_visibility() {
+ ret void
+}
+; CHECK: define void @hidden_visibility() {
+
+define protected void @protected_visibility() {
+ ret void
+}
+; CHECK: define void @protected_visibility() {
+
define void @call_attrs() {
call fastcc void @func_attrs(i32 inreg 10, i32 zeroext 20) noreturn nounwind readonly
ret void