Skip to content

Commit 4cadbfe

Browse files
When building shared objects, don't export non-canonical definitions
Fixes #381
1 parent 0efeebc commit 4cadbfe

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

libwild/src/layout.rs

+9
Original file line numberDiff line numberDiff line change
@@ -3643,15 +3643,24 @@ impl<'data> ObjectLayoutState<'data> {
36433643
for (sym_index, sym) in self.object.symbols.enumerate() {
36443644
if can_export_symbol(sym) {
36453645
let symbol_id = self.symbol_id_range().input_to_id(sym_index);
3646+
3647+
if !resources.symbol_db.is_canonical(symbol_id) {
3648+
continue;
3649+
}
3650+
36463651
let value_flags = resources.symbol_db.local_symbol_value_flags(symbol_id);
3652+
36473653
if value_flags.contains(ValueFlags::DOWNGRADE_TO_LOCAL) {
36483654
continue;
36493655
}
3656+
36503657
let old_flags = resources.symbol_resolution_flags[symbol_id.as_usize()]
36513658
.fetch_or(ResolutionFlags::EXPORT_DYNAMIC);
3659+
36523660
if old_flags.is_empty() {
36533661
self.load_symbol::<A>(common, symbol_id, resources, queue)?;
36543662
}
3663+
36553664
if !old_flags.contains(ResolutionFlags::EXPORT_DYNAMIC) {
36563665
export_dynamic(common, symbol_id, resources)?;
36573666
}

wild/tests/sources/libc-integration-0.c

+5
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ int sometimes_weak_fn(void) {
7272
int black_box(int v) {
7373
return v;
7474
}
75+
76+
// This function is also defined in libc-integration-0b.c. The definition here should be used.
77+
int __attribute__ ((weak)) weak_fn3(void) {
78+
return 15;
79+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This function is also defined in libc-integration-0.c. The other definition should be used.
2+
int __attribute__ ((weak)) weak_fn3(void) {
3+
return 16;
4+
}

wild/tests/sources/libc-integration.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//#Cross: false
1616

1717
//#AbstractConfig:shared:default
18-
//#Shared:libc-integration-0.c
18+
//#Shared:libc-integration-0.c,libc-integration-0b.c
1919
//#Shared:libc-integration-1.c
2020
// Each binary links against shared objects created by that linker. So different names are expected.
2121
//#DiffIgnore:.dynamic.DT_NEEDED
@@ -92,6 +92,7 @@ void set_tvar2(int v);
9292

9393
int __attribute__ ((weak)) weak_fn1(void);
9494
int __attribute__ ((weak)) weak_fn2(void);
95+
int __attribute__ ((weak)) weak_fn3(void);
9596

9697
int __attribute__ ((weak)) sometimes_weak_fn(void) {
9798
return 7;
@@ -273,5 +274,9 @@ int main() {
273274
}
274275
#endif
275276

277+
if (weak_fn3() != 15) {
278+
return 123;
279+
}
280+
276281
return 42;
277282
}

0 commit comments

Comments
 (0)