| ... | ... | @@ -1506,6 +1506,9 @@ pub const Object = struct { |
| 1506 | 1506 | variable.setSection(try o.builder.string(section_slice), &o.builder); |
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | const arch = comp.root_mod.resolved_target.result.cpu.arch; |
| 1510 | const is_nvptx = arch == .nvptx or arch == .nvptx64; |
| 1511 | |
| 1509 | 1512 | const llvm_global_ty = llvm_global.typeOf(&o.builder); |
| 1510 | 1513 | |
| 1511 | 1514 | // All exports are represented as aliases to the original global. |
| ... | ... | @@ -1513,7 +1516,7 @@ pub const Object = struct { |
| 1513 | 1516 | // TODO: we currently do not delete old exports. To do that we'll need to track which |
| 1514 | 1517 | // globals actually *are* exports. |
| 1515 | 1518 | |
| 1516 | | for (export_indices) |export_idx| { |
| 1519 | for (export_indices, 0..) |export_idx, export_i| { |
| 1517 | 1520 | const exp = export_idx.ptr(zcu); |
| 1518 | 1521 | const exp_name = try o.builder.strtabString(exp.opts.name.toSlice(ip)); |
| 1519 | 1522 | |
| ... | ... | @@ -1524,6 +1527,15 @@ pub const Object = struct { |
| 1524 | 1527 | // The name, aliasee, and type will be set within this block. Other properties of the |
| 1525 | 1528 | // alias will be set below. |
| 1526 | 1529 | const alias_global: Builder.Global.Index = global: { |
| 1530 | |
| 1531 | // WORKAROUND (see https://github.com/llvm/llvm-project/issues/213504) |
| 1532 | // LLVM throws "NVPTX aliasee must be a non-kernel function definition" |
| 1533 | // if we try to alias a kernel, so we just rename the global directly. |
| 1534 | if (is_nvptx and export_i == 0) { |
| 1535 | try llvm_global.rename(exp_name, &o.builder); |
| 1536 | break :global llvm_global; |
| 1537 | } |
| 1538 | |
| 1527 | 1539 | const existing_global = o.builder.getGlobal(exp_name) orelse { |
| 1528 | 1540 | // There is no existing global with this name, so make a new alias. |
| 1529 | 1541 | const alias = try o.builder.addAlias( |