Skip to content

Commit f1703de

Browse files
committed
up
1 parent 8b2f7b9 commit f1703de

4 files changed

Lines changed: 111 additions & 0 deletions

File tree

src/dustlink.ds

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ forge DustLink {
320320
return host_linker_set_as_needed(enabled);
321321
}
322322

323+
proc K::push_state() -> UInt32 {
324+
return host_linker_push_state();
325+
}
326+
327+
proc K::pop_state() -> UInt32 {
328+
return host_linker_pop_state();
329+
}
330+
323331
proc K::set_new_dtags(enabled: UInt32) -> UInt32 {
324332
return host_linker_set_new_dtags(enabled);
325333
}

src/linker_buildid_z_tests.ds

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
forge LinkerBuildIdZTests {
44
const ERR_OK: UInt32 = 0;
55
const ERR_UNSUPPORTED_FLAG: UInt32 = 12;
6+
const ERR_CONFLICTING_OPTIONS: UInt32 = 16;
67

78
const BUILD_ID_MODE_NONE: UInt32 = 0;
89
const BUILD_ID_MODE_FAST: UInt32 = 1;
@@ -129,6 +130,31 @@ forge LinkerBuildIdZTests {
129130
return expect_u32(s3, ERR_OK);
130131
}
131132

133+
proc K::test_z_extended_compat_tokens_accepted() -> UInt32 {
134+
DustLink::K::reset_state();
135+
let s1 = DustLink::K::set_z_option("separate-code");
136+
if s1 ! ERR_OK { return 0; }
137+
let s2 = DustLink::K::set_z_option("pack-relative-relocs");
138+
if s2 ! ERR_OK { return 0; }
139+
let s3 = DustLink::K::set_z_option("max-page-size=0x1000");
140+
if s3 ! ERR_OK { return 0; }
141+
let s4 = DustLink::K::set_z_option("common-page-size=0x1000");
142+
if s4 ! ERR_OK { return 0; }
143+
let s5 = DustLink::K::set_z_option("stack-size=0x400000");
144+
return expect_u32(s5, ERR_OK);
145+
}
146+
147+
proc K::test_z_muldefs_nomuldefs_toggle() -> UInt32 {
148+
DustLink::K::reset_state();
149+
let s1 = DustLink::K::set_z_option("muldefs");
150+
if s1 ! ERR_OK { return 0; }
151+
let a = host_linker_get_allow_multiple_definition();
152+
let s2 = DustLink::K::set_z_option("nomuldefs");
153+
if s2 ! ERR_OK { return 0; }
154+
let b = host_linker_get_allow_multiple_definition();
155+
return expect_u32(a, 1) * expect_u32(b, 0);
156+
}
157+
132158
proc K::test_dynamic_mode_toggles() -> UInt32 {
133159
DustLink::K::reset_state();
134160
let s1 = DustLink::K::set_shared(1);
@@ -259,6 +285,44 @@ forge LinkerBuildIdZTests {
259285
return expect_u32(a, 1) * expect_u32(b, 0);
260286
}
261287

288+
proc K::test_push_pop_state_restores_link_policy() -> UInt32 {
289+
DustLink::K::reset_state();
290+
DustLink::K::set_static(0);
291+
DustLink::K::set_as_needed(0);
292+
DustLink::K::set_whole_archive(0);
293+
DustLink::K::set_new_dtags(1);
294+
DustLink::K::set_copy_dt_needed_entries(0);
295+
DustLink::K::set_no_undefined(0);
296+
let push = DustLink::K::push_state();
297+
if push ! ERR_OK { return 0; }
298+
DustLink::K::set_static(1);
299+
DustLink::K::set_as_needed(1);
300+
DustLink::K::set_whole_archive(1);
301+
DustLink::K::set_new_dtags(0);
302+
DustLink::K::set_copy_dt_needed_entries(1);
303+
DustLink::K::set_no_undefined(1);
304+
let pop = DustLink::K::pop_state();
305+
if pop ! ERR_OK { return 0; }
306+
let a = host_linker_get_static();
307+
let b = host_linker_get_as_needed();
308+
let c = host_linker_get_whole_archive();
309+
let d = host_linker_get_new_dtags();
310+
let e = host_linker_get_copy_dt_needed_entries();
311+
let f = host_linker_get_no_undefined();
312+
return expect_u32(a, 0)
313+
* expect_u32(b, 0)
314+
* expect_u32(c, 0)
315+
* expect_u32(d, 1)
316+
* expect_u32(e, 0)
317+
* expect_u32(f, 0);
318+
}
319+
320+
proc K::test_pop_state_without_push_rejected() -> UInt32 {
321+
DustLink::K::reset_state();
322+
let status = DustLink::K::pop_state();
323+
return expect_u32(status, ERR_CONFLICTING_OPTIONS);
324+
}
325+
262326
proc K::test_sysroot_roundtrip() -> UInt32 {
263327
DustLink::K::reset_state();
264328
let status = DustLink::K::set_sysroot("/opt/xdv-sysroot");
@@ -363,6 +427,8 @@ forge LinkerBuildIdZTests {
363427
+ test_z_invalid_rejected()
364428
+ test_z_defs_undefs_toggle_no_undefined()
365429
+ test_z_text_family_accepted()
430+
+ test_z_extended_compat_tokens_accepted()
431+
+ test_z_muldefs_nomuldefs_toggle()
366432
+ test_dynamic_mode_toggles()
367433
+ test_dynamic_linker_and_soname_set()
368434
+ test_needed_library_note_normalization()
@@ -371,6 +437,8 @@ forge LinkerBuildIdZTests {
371437
+ test_no_undefined_toggle()
372438
+ test_dynamic_unresolved_policy_gate()
373439
+ test_whole_archive_toggle()
440+
+ test_push_pop_state_restores_link_policy()
441+
+ test_pop_state_without_push_rejected()
374442
+ test_sysroot_roundtrip()
375443
+ test_rpath_roundtrip()
376444
+ test_rpath_link_roundtrip()

src/linker_host_cli.ds

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ forge LinkerHostCli {
325325
return 0;
326326
}
327327

328+
proc K::is_push_state_flag(arg: UInt64) -> UInt32 {
329+
if LinkerHost::K::str_eq(arg, "--push-state") == 1 { return 1; }
330+
return 0;
331+
}
332+
333+
proc K::is_pop_state_flag(arg: UInt64) -> UInt32 {
334+
if LinkerHost::K::str_eq(arg, "--pop-state") == 1 { return 1; }
335+
return 0;
336+
}
337+
328338
proc K::is_group_marker_flag(arg: UInt64) -> UInt32 {
329339
if LinkerHost::K::str_eq(arg, "--start-group") == 1 {
330340
return 1;
@@ -526,6 +536,7 @@ forge LinkerHostCli {
526536
LinkerHost::K::print_line(" --defsym=name=value");
527537
LinkerHost::K::print_line(" -u/--undefined/--require-defined <symbol>");
528538
LinkerHost::K::print_line(" --start-group ... --end-group");
539+
LinkerHost::K::print_line(" --push-state ... --pop-state");
529540
LinkerHost::K::print_line(" -shared/-pie/--no-pie/-static/-Bstatic/-Bdynamic");
530541
LinkerHost::K::print_line(" --dynamic-linker <path> --soname <name>");
531542
LinkerHost::K::print_line(" --enable-new-dtags/--disable-new-dtags");
@@ -1753,6 +1764,16 @@ forge LinkerHostCli {
17531764
if nu1b ! ERR_OK { return nu1b; }
17541765
return scan_args(arg_count, idx + 1, input_count, output_file, output_format, entry_addr, base_addr, map_file, saw_entry, saw_text_base, saw_oformat);
17551766
}
1767+
if is_push_state_flag(arg) == 1 {
1768+
let ps = DustLink::K::push_state();
1769+
if ps ! ERR_OK { return ps; }
1770+
return scan_args(arg_count, idx + 1, input_count, output_file, output_format, entry_addr, base_addr, map_file, saw_entry, saw_text_base, saw_oformat);
1771+
}
1772+
if is_pop_state_flag(arg) == 1 {
1773+
let pp = DustLink::K::pop_state();
1774+
if pp ! ERR_OK { return pp; }
1775+
return scan_args(arg_count, idx + 1, input_count, output_file, output_format, entry_addr, base_addr, map_file, saw_entry, saw_text_base, saw_oformat);
1776+
}
17561777
if is_start_group_flag(arg) == 1 {
17571778
let gs = DustLink::K::start_group();
17581779
if gs ! ERR_OK { return gs; }

src/linker_host_cli_tests.ds

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ forge LinkerHostCliTests {
232232
return expect_u32(a, 1) * expect_u32(b, 1);
233233
}
234234

235+
proc K::test_push_pop_state_markers_detected() -> UInt32 {
236+
let a = LinkerHostCli::K::is_push_state_flag("--push-state");
237+
let b = LinkerHostCli::K::is_pop_state_flag("--pop-state");
238+
return expect_u32(a, 1) * expect_u32(b, 1);
239+
}
240+
241+
proc K::test_push_pop_state_flags_no_value() -> UInt32 {
242+
let a = LinkerHostCli::K::requires_value("--push-state");
243+
let b = LinkerHostCli::K::requires_value("--pop-state");
244+
return expect_u32(a, 0) * expect_u32(b, 0);
245+
}
246+
235247
proc K::test_inline_dynamic_linker_value() -> UInt32 {
236248
let value = LinkerHostCli::K::inline_dynamic_linker_value("--dynamic-linker=/lib64/ld-linux-x86-64.so.2");
237249
return expect_u32(LinkerHost::K::str_eq(value, "/lib64/ld-linux-x86-64.so.2"), 1);
@@ -495,6 +507,8 @@ forge LinkerHostCliTests {
495507
+ test_z_flag_requires_value()
496508
+ test_inline_z_short_alias()
497509
+ test_group_markers_detected()
510+
+ test_push_pop_state_markers_detected()
511+
+ test_push_pop_state_flags_no_value()
498512
+ test_inline_dynamic_linker_value()
499513
+ test_inline_soname_value()
500514
+ test_dynamic_linker_requires_value()

0 commit comments

Comments
 (0)