summaryrefslogtreecommitdiff
path: root/shill_export.h
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@chromium.org>2014-11-17 10:26:35 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-18 09:10:41 +0000
commitba24e6fd0f0f2b974e0e73039d7d92bb475f6857 (patch)
treeae02d3a5ee5b5883a073ead57850df024002bb14 /shill_export.h
parent66bddc67c71dd197211ca08c5a4835bd6cfa5ed2 (diff)
downloadshill-ba24e6fd0f0f2b974e0e73039d7d92bb475f6857.tar.gz
shill: Disable automatic symbol exports from libshill-net
Using -fvisibility=default flag in libshill-net causes a lot of uneeded symbols to be exported from the shared library. Removed the flag from the GYP file for libshill-net and instead added SHILL_EXPORT macro to be added to classes, variables and methods to be exported from the libraries explicitly. Also added SHILL_PRIVATE attribute to explicitly hide a symbol which can be used on some member of a class that is otherwise exported. BUG=chromium:433600 TEST=USE="clang asan" FEATURES=test emerge-$BOARD shill Change-Id: I16928737dde6bc5b97785773f6ed0f940f301f62 Reviewed-on: https://chromium-review.googlesource.com/230220 Reviewed-by: Peter Qiu <zqiu@chromium.org> Commit-Queue: Peter Qiu <zqiu@chromium.org> Tested-by: Peter Qiu <zqiu@chromium.org>
Diffstat (limited to 'shill_export.h')
-rw-r--r--shill_export.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/shill_export.h b/shill_export.h
new file mode 100644
index 00000000..9947daa6
--- /dev/null
+++ b/shill_export.h
@@ -0,0 +1,60 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_SHILL_EXPORT_H_
+#define SHILL_SHILL_EXPORT_H_
+
+// Use SHILL_EXPORT attribute to decorate your classes, methods and variables
+// that need to be exported out of libshill By default, any symbol not
+// explicitly marked with SHILL_EXPORT attribute is not exported.
+
+// Put SHILL_EXPORT in front of methods or variables and in between the
+// class and the tag name:
+/*
+
+SHILL_EXPORT void foo();
+
+class SHILL_EXPORT Bar {
+ public:
+ void baz(); // Exported since it is a member of an exported class.
+};
+
+*/
+
+// Exporting a class automatically exports all of its members. However there are
+// no export entries for non-static member variables since they are not accessed
+// directly, but rather through "this" pointer. Class methods, type information,
+// virtual table (if any), and static member variables are exported.
+
+// Finally, template functions and template members of a class may not be
+// inlined by the compiler automatically and the out-of-line version will not
+// be exported and fail to link. Marking those inline explicitly might help.
+// Alternatively, exporting specific instantiation of the template could be
+// used with "extern template" and combining this with SHILL_EXPORT.
+#define SHILL_EXPORT __attribute__((__visibility__("default")))
+
+// On occasion you might need to disable exporting a particular symbol if
+// you don't want the clients to see it. For example, you can explicitly
+// hide a member of an exported class:
+/*
+
+class SHILL_EXPORT Foo {
+ public:
+ void bar(); // Exported since it is a member of an exported class.
+
+ private:
+ SHILL_PRIVATE void baz(); // Explicitly removed from export table.
+};
+
+*/
+
+// Note that even though a class may have a private member it doesn't mean
+// that it must not be exported, since the compiler might still need it.
+// For example, an inline public method calling a private method will not link
+// if that private method is not exported.
+// So be careful with hiding members if you don't want to deal with obscure
+// linker errors.
+#define SHILL_PRIVATE __attribute__((__visibility__("hidden")))
+
+#endif // SHILL_SHILL_EXPORT_H_