aboutsummaryrefslogtreecommitdiff
path: root/libphobos/libdruntime
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-06-15 19:44:36 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2022-06-15 20:11:04 +0200
commit636b01ab4910da0b96d844301fea1a2b56c5344d (patch)
tree480d97c9a670995fe519be3a7f8b86c5e97e50cb /libphobos/libdruntime
parent49d14a841fd9a798fe6d68ae49c6fbb753d21032 (diff)
d: Add `@visibility' and `@hidden' attributes.
The `@visibility' attribute is functionality the same as `__attribute__((visibility))', and `@hidden' is a convenience alias to `@visibility("hidden")' defined in the `gcc.attributes' module. As the visibility of a symbol is also indirectly controlled by the `export' keyword, the handling of this in the code generation pass has been improved so that conflicts will be appropriately diagnosed. gcc/d/ChangeLog: * d-attribs.cc (d_langhook_attribute_table): Add visibility. (insert_type_attribute): Use decl_attributes instead of merge_attributes. (insert_decl_attribute): Likewise. (apply_user_attributes): Do nothing when no UDAs applied. (d_handle_visibility_attribute): New function. * d-gimplify.cc (d_gimplify_binary_expr): Adjust. * d-tree.h (set_visibility_for_decl): Declare. * decl.cc (get_symbol_decl): Move setting of visibility flags to... (set_visibility_for_decl): ... here. New function. * types.cc (TypeVisitor::visit (TypeStruct *)): Call set_visibility_for_decl(). (TypeVisitor::visit (TypeClass *)): Likewise. gcc/testsuite/ChangeLog: * gdc.dg/attr_visibility1.d: New test. * gdc.dg/attr_visibility2.d: New test. * gdc.dg/attr_visibility3.d: New test. libphobos/ChangeLog: * libdruntime/gcc/attributes.d (visibility): Define. (hidden): Define.
Diffstat (limited to 'libphobos/libdruntime')
-rw-r--r--libphobos/libdruntime/gcc/attributes.d34
1 files changed, 34 insertions, 0 deletions
diff --git a/libphobos/libdruntime/gcc/attributes.d b/libphobos/libdruntime/gcc/attributes.d
index 09f684cd44e..ca066cef822 100644
--- a/libphobos/libdruntime/gcc/attributes.d
+++ b/libphobos/libdruntime/gcc/attributes.d
@@ -425,6 +425,30 @@ auto target_clones(A...)(A arguments)
enum used = attribute("used");
/**
+ * The `@visibility` attribute affects the linkage of the declaration to which
+ * it is attached. It can be applied to variables, types, and functions.
+ *
+ * There are four supported visibility_type values: `default`, `hidden`,
+ * `protected`, or `internal` visibility.
+ *
+ * Example:
+ * ---
+ * import gcc.attributes;
+ *
+ * @visibility("protected") void func() { }
+ * ---
+ */
+auto visibility(string visibilityName)
+{
+ return attribute("visibility", visibilityName);
+}
+
+auto visibility(A...)(A arguments)
+{
+ assert(false, "visibility attribute argument not a string constant");
+}
+
+/**
* The `@weak` attribute causes a declaration of an external symbol to be
* emitted as a weak symbol rather than a global. This is primarily useful in
* defining library functions that can be overridden in user code, though it can
@@ -543,6 +567,16 @@ enum dynamicCompileEmit = false;
enum fastmath = optimize("Ofast");
/**
+ * Sets the visibility of a function or global variable to "hidden".
+ * Such symbols aren't directly accessible from outside the DSO
+ * (executable or DLL/.so/.dylib) and are resolved inside the DSO
+ * during linking. If unreferenced within the DSO, the linker can
+ * strip a hidden symbol.
+ * An `export` visibility overrides this attribute.
+ */
+enum hidden = visibility("hidden");
+
+/**
* Adds GCC's "naked" attribute to a function, disabling function prologue /
* epilogue emission.
* Intended to be used in combination with basic `asm` statement. While using