| ... | @@ -722,6 +722,10 @@ pub const Object = struct { | ... | @@ -722,6 +722,10 @@ pub const Object = struct { |
| 722 | dg.addFnAttrString(llvm_func, "no-stack-arg-probe", ""); | 722 | dg.addFnAttrString(llvm_func, "no-stack-arg-probe", ""); |
| 723 | } | 723 | } |
| 724 | | 724 | |
| | 725 | if (decl.@"linksection") |section| { |
| | 726 | llvm_func.setSection(section); |
| | 727 | } |
| | 728 | |
| 725 | // Remove all the basic blocks of a function in order to start over, generating | 729 | // Remove all the basic blocks of a function in order to start over, generating |
| 726 | // LLVM IR from an empty function body. | 730 | // LLVM IR from an empty function body. |
| 727 | while (llvm_func.getFirstBasicBlock()) |bb| { | 731 | while (llvm_func.getFirstBasicBlock()) |bb| { |
| ... | @@ -1107,6 +1111,11 @@ pub const Object = struct { | ... | @@ -1107,6 +1111,11 @@ pub const Object = struct { |
| 1107 | .hidden => llvm_global.setVisibility(.Hidden), | 1111 | .hidden => llvm_global.setVisibility(.Hidden), |
| 1108 | .protected => llvm_global.setVisibility(.Protected), | 1112 | .protected => llvm_global.setVisibility(.Protected), |
| 1109 | } | 1113 | } |
| | 1114 | if (exports[0].options.section) |section| { |
| | 1115 | const section_z = try module.gpa.dupeZ(u8, section); |
| | 1116 | defer module.gpa.free(section_z); |
| | 1117 | llvm_global.setSection(section_z); |
| | 1118 | } |
| 1110 | if (decl.val.castTag(.variable)) |variable| { | 1119 | if (decl.val.castTag(.variable)) |variable| { |
| 1111 | if (variable.data.is_threadlocal) { | 1120 | if (variable.data.is_threadlocal) { |
| 1112 | llvm_global.setThreadLocalMode(.GeneralDynamicTLSModel); | 1121 | llvm_global.setThreadLocalMode(.GeneralDynamicTLSModel); |
| ... | @@ -2183,6 +2192,7 @@ pub const DeclGen = struct { | ... | @@ -2183,6 +2192,7 @@ pub const DeclGen = struct { |
| 2183 | const target = dg.module.getTarget(); | 2192 | const target = dg.module.getTarget(); |
| 2184 | var global = try dg.resolveGlobalDecl(decl_index); | 2193 | var global = try dg.resolveGlobalDecl(decl_index); |
| 2185 | global.setAlignment(decl.getAlignment(target)); | 2194 | global.setAlignment(decl.getAlignment(target)); |
| | 2195 | if (decl.@"linksection") |section| global.setSection(section); |
| 2186 | assert(decl.has_tv); | 2196 | assert(decl.has_tv); |
| 2187 | const init_val = if (decl.val.castTag(.variable)) |payload| init_val: { | 2197 | const init_val = if (decl.val.castTag(.variable)) |payload| init_val: { |
| 2188 | const variable = payload.data; | 2198 | const variable = payload.data; |
| ... | @@ -2216,6 +2226,7 @@ pub const DeclGen = struct { | ... | @@ -2216,6 +2226,7 @@ pub const DeclGen = struct { |
| 2216 | new_global.setLinkage(global.getLinkage()); | 2226 | new_global.setLinkage(global.getLinkage()); |
| 2217 | new_global.setUnnamedAddr(global.getUnnamedAddress()); | 2227 | new_global.setUnnamedAddr(global.getUnnamedAddress()); |
| 2218 | new_global.setAlignment(global.getAlignment()); | 2228 | new_global.setAlignment(global.getAlignment()); |
| | 2229 | if (decl.@"linksection") |section| new_global.setSection(section); |
| 2219 | new_global.setInitializer(llvm_init); | 2230 | new_global.setInitializer(llvm_init); |
| 2220 | // replaceAllUsesWith requires the type to be unchanged. So we bitcast | 2231 | // replaceAllUsesWith requires the type to be unchanged. So we bitcast |
| 2221 | // the new global to the old type and use that as the thing to replace | 2232 | // the new global to the old type and use that as the thing to replace |