feat: duplicate C exports across #import c units are a compile diagnostic
All units share one link namespace (per-unit isolation is PLAN-C C3.2, deferred), so a symbol defined by two units previously died inside the JIT dylib link or the AOT link with raw linker spew. The clang shim gains sx_clang_object_exported_symbols (llvm::object scan: defined + global, format-specific excluded) and compileCToObjects cross-checks every unit object — collisions name both source files. Scan failures are non-fatal; the linker remains the backstop. Covers JIT and native AOT; the emcc path still relies on wasm-ld's own error.
This commit is contained in:
20
examples/1628-cimport-duplicate-export.sx
Normal file
20
examples/1628-cimport-duplicate-export.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// Two `#import c` units defining the same exported symbol is a
|
||||
// compile-time diagnostic naming both sources — previously it died
|
||||
// inside the JIT dylib link (or the AOT link) with raw linker spew.
|
||||
// All units share one link namespace; per-unit symbol isolation is
|
||||
// PLAN-C C3.2 (deferred).
|
||||
#import "modules/std.sx";
|
||||
|
||||
ua :: #import c {
|
||||
#source "1628-cimport-duplicate-export/a.c";
|
||||
};
|
||||
ub :: #import c {
|
||||
#source "1628-cimport-duplicate-export/b.c";
|
||||
};
|
||||
|
||||
clash :: () -> i32 #foreign ua "clash";
|
||||
|
||||
main :: () -> i32 {
|
||||
print("{}\n", clash());
|
||||
0
|
||||
}
|
||||
1
examples/1628-cimport-duplicate-export/a.c
Normal file
1
examples/1628-cimport-duplicate-export/a.c
Normal file
@@ -0,0 +1 @@
|
||||
int clash(void) { return 1; }
|
||||
1
examples/1628-cimport-duplicate-export/b.c
Normal file
1
examples/1628-cimport-duplicate-export/b.c
Normal file
@@ -0,0 +1 @@
|
||||
int clash(void) { return 2; }
|
||||
1
examples/expected/1628-cimport-duplicate-export.exit
Normal file
1
examples/expected/1628-cimport-duplicate-export.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
1
examples/expected/1628-cimport-duplicate-export.stderr
Normal file
1
examples/expected/1628-cimport-duplicate-export.stderr
Normal file
@@ -0,0 +1 @@
|
||||
error: C symbol 'clash' is defined by multiple '#import c' sources: 'examples/1628-cimport-duplicate-export/a.c' and 'examples/1628-cimport-duplicate-export/b.c' — all units share one link namespace
|
||||
Reference in New Issue
Block a user