Test assembly external text fixups

2e5fdaa8b5a72f3cfd8d7e715319ad585786e911ac3bb6996c07c028bbd99535
Cover assembler output for unresolved text references that are meant to
be resolved later by the whole-program RV64 emitter. The test checks
`tail` and `la` references to the exported `::default` symbol and
verifies the recorded fixup shape.

Keep data-symbol references strict by asserting that an unresolved
`.dword` label still fails assembly instead of becoming an external text
relocation.
Alexis Sellier committed ago 1 parent 9e960a2c
lib/std/arch/rv64/asm/tests.rad +24 -0
101 101
    try testing::expect(not program.symbols[0].isExported);
102 102
    try testing::expect(program.symbols[1].isExported);
103 103
    try testing::expect(program.symbols[2].isExported);
104 104
}
105 105
106 +
@test fn testAssembleExternalTextFixups() throws (testing::TestError) {
107 +
    let program = try assembleSource(
108 +
        ".text;\ntail @\"::default\";\nla %t0 @\"::default\";\n"
109 +
    );
110 +
    try testing::expect(program.externalFixups.len == 2);
111 +
112 +
    let case super::FixupInfo::Jal { rd, index } = program.externalFixups[0].info else {
113 +
        throw testing::TestError::Failed;
114 +
    };
115 +
    try testing::expect(mem::eq(program.externalFixups[0].symbol, "::default"));
116 +
    try testing::expect(rd == rv64::ZERO);
117 +
    try testing::expect(index == 0);
118 +
119 +
    let case super::FixupInfo::Addr { rd: addrRd, index: addrIndex } = program.externalFixups[1].info else {
120 +
        throw testing::TestError::Failed;
121 +
    };
122 +
    try testing::expect(mem::eq(program.externalFixups[1].symbol, "::default"));
123 +
    try testing::expect(addrRd == rv64::T0);
124 +
    try testing::expect(addrIndex == 1);
125 +
}
126 +
106 127
@test fn testAssembleInvalidOperandsFail() throws (testing::TestError) {
107 128
    try expectAssembleFail(
108 129
        ".text;\nbeq %a0 %a1 @missing;\n"
109 130
    );
110 131
    try expectAssembleFail(
117 138
        ".text;\nli %a0 UNKNOWN;\n"
118 139
    );
119 140
    try expectAssembleFail(
120 141
        ".text;\n@start\nj start;\n"
121 142
    );
143 +
    try expectAssembleFail(
144 +
        ".data;\n.dword @missing;\n"
145 +
    );
122 146
}
123 147
124 148
@test fn testAssembleInvalidSyntaxFails() throws (testing::TestError) {
125 149
    try expectAssembleFail(
126 150
        ".text;\n@dup\n@dup\nret;\n"