diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-08-10 14:08:09 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-08-10 16:43:30 -0700 |
| commit | d267f0f968c97d77d8434ef9918c71fb4c11f45d (patch) | |
| tree | 7ccb96996094065e66b21a59f5c1eff7a8268806 /src/codegen/llvm.zig | |
| parent | e8d02c5b90c0833401a70cc797a28da57a356927 (diff) | |
| download | zig-d267f0f968c97d77d8434ef9918c71fb4c11f45d.tar.gz zig-d267f0f968c97d77d8434ef9918c71fb4c11f45d.zip | |
LLVM: respect linksection for exported variables
Diffstat (limited to 'src/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 6d2922ea3f..aa846f4247 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -722,6 +722,10 @@ pub const Object = struct { dg.addFnAttrString(llvm_func, "no-stack-arg-probe", ""); } + if (decl.@"linksection") |section| { + llvm_func.setSection(section); + } + // Remove all the basic blocks of a function in order to start over, generating // LLVM IR from an empty function body. while (llvm_func.getFirstBasicBlock()) |bb| { @@ -1107,6 +1111,11 @@ pub const Object = struct { .hidden => llvm_global.setVisibility(.Hidden), .protected => llvm_global.setVisibility(.Protected), } + if (exports[0].options.section) |section| { + const section_z = try module.gpa.dupeZ(u8, section); + defer module.gpa.free(section_z); + llvm_global.setSection(section_z); + } if (decl.val.castTag(.variable)) |variable| { if (variable.data.is_threadlocal) { llvm_global.setThreadLocalMode(.GeneralDynamicTLSModel); @@ -2183,6 +2192,7 @@ pub const DeclGen = struct { const target = dg.module.getTarget(); var global = try dg.resolveGlobalDecl(decl_index); global.setAlignment(decl.getAlignment(target)); + if (decl.@"linksection") |section| global.setSection(section); assert(decl.has_tv); const init_val = if (decl.val.castTag(.variable)) |payload| init_val: { const variable = payload.data; @@ -2216,6 +2226,7 @@ pub const DeclGen = struct { new_global.setLinkage(global.getLinkage()); new_global.setUnnamedAddr(global.getUnnamedAddress()); new_global.setAlignment(global.getAlignment()); + if (decl.@"linksection") |section| new_global.setSection(section); new_global.setInitializer(llvm_init); // replaceAllUsesWith requires the type to be unchanged. So we bitcast // the new global to the old type and use that as the thing to replace |
