diff options
| author | Takeshi Yoneda <takeshi@tetrate.io> | 2021-09-24 22:14:53 +0900 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-05-10 15:21:48 -0700 |
| commit | 9654a54d4a2729200d38dbb6eec827cb03dc0f90 (patch) | |
| tree | 3b96d72cca0cb34c99f9a60f4b093e1fa4052dea /src/stage1/codegen.cpp | |
| parent | 67c4b16d6e27f1d81e2e2f837bd53d958b9baa33 (diff) | |
| download | zig-9654a54d4a2729200d38dbb6eec827cb03dc0f90.tar.gz zig-9654a54d4a2729200d38dbb6eec827cb03dc0f90.zip | |
Add Visibility field to ExportOptions.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Diffstat (limited to 'src/stage1/codegen.cpp')
| -rw-r--r-- | src/stage1/codegen.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index d101030c33..dece8e7348 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -242,6 +242,18 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id, bool is_extern) { zig_unreachable(); } +static LLVMVisibility to_llvm_visibility(GlobalVisibilityId id) { + switch (id) { + case GlobalVisibilityIdDefault: + return LLVMDefaultVisibility; + case GlobalVisibilityIdHidden: + return LLVMHiddenVisibility; + case GlobalVisibilityIdProtected: + return LLVMProtectedVisibility; + } + zig_unreachable(); +} + struct CalcLLVMFieldIndex { uint32_t offset; uint32_t field_index; @@ -400,6 +412,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { const char *unmangled_name = buf_ptr(&fn->symbol_name); const char *symbol_name; GlobalLinkageId linkage; + GlobalVisibilityId visibility = GlobalVisibilityIdDefault; if (fn->body_node == nullptr) { symbol_name = unmangled_name; linkage = GlobalLinkageIdStrong; @@ -410,6 +423,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { GlobalExport *fn_export = &fn->export_list.items[0]; symbol_name = buf_ptr(&fn_export->name); linkage = fn_export->linkage; + visibility = fn_export->visibility; } CallingConvention cc = fn->type_entry->data.fn.fn_type_id.cc; @@ -532,6 +546,8 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { LLVMSetUnnamedAddr(llvm_fn, true); } + LLVMSetVisibility(llvm_fn, to_llvm_visibility(visibility)); + ZigType *return_type = fn_type->data.fn.fn_type_id.return_type; if (return_type->id == ZigTypeIdUnreachable) { addLLVMFnAttr(llvm_fn, "noreturn"); @@ -8951,6 +8967,7 @@ static void do_code_gen(CodeGen *g) { assert(var->decl_node); GlobalLinkageId linkage; + GlobalVisibilityId visibility = GlobalVisibilityIdDefault; const char *unmangled_name = var->name; const char *symbol_name; if (var->export_list.length == 0) { @@ -8965,6 +8982,7 @@ static void do_code_gen(CodeGen *g) { GlobalExport *global_export = &var->export_list.items[0]; symbol_name = buf_ptr(&global_export->name); linkage = global_export->linkage; + visibility = global_export->visibility; } LLVMValueRef global_value; @@ -9010,6 +9028,8 @@ static void do_code_gen(CodeGen *g) { set_global_tls(g, var, global_value); } + LLVMSetVisibility(global_value, to_llvm_visibility(visibility)); + var->value_ref = global_value; for (size_t export_i = 1; export_i < var->export_list.length; export_i += 1) { |
