Same 46 bytes, same relocation, wrong table

L3SeniorDesign10 minSystem designDesign review

RolesAgent Systems EngineeringAI Evaluation and ReliabilityLLM Product Engineering

The question

Design the second leg of a rebuild proof: build every candidate under the compiler and flags that produced the original, then compare it with the original function. Eight candidates are on the table, among them a pair of percent_change rebuilds whose source lines are written differently, a grade candidate whose 46 code bytes and relocation shape match the original but whose case 10 returns 3, and candidates whose relocation addend differs from the original. Say what the compare does at each step, which candidate each step stops, and what a pass means.

Answer it first, aloud or on paper. Then open the answer.

The answer

Show short answer

Three steps in order: mask every relocation field by zeroing its bytes on both sides and compare the code; compare the relocation records by offset, type and target section, not by addend, because the original says .rodata+0x10 and every candidate says .rodata-0x4 and that is a different table position, not a different function; then read the bytes each relocation points at, here five 4-byte words, and compare them. The wrong-constant candidate passes the first two steps and fails only the third, 1, 2, 3, 4, 4 against 1, 2, 3, 4, 3. A pass proves that this compiler with these flags produced the same code and the same referenced data from the candidate; it does not prove that the candidate is the original source text, since the two percent_change rebuilds with different text compile to identical 16 bytes.

Show full answer

Where each candidate stops

CandidateSizeMasked bytesRecordsTableStatus
percent_change_mul_first16 and 16equalnonenonepass
percent_change_split16 and 16equalnonenonepass
percent_change_wide16 and 26size differsnonenonefail
percent_change_div_first16 and 18size differsnonenonefail
grade_switch46 and 46equalsame shapeequalpass
grade_table46 and 46equalsame shapeequalpass
grade_thresholds46 and 39size differs1 against 0nonefail
grade_case10_wrong46 and 46equalsame shapedifferfail

Size is a diagnostic and never an acceptance: a recorded reconstruction project reports a candidate with the right length and hundreds of differing bytes.

Why mask when the field is already zero

In a RELA object the addend lives in the record and the four field bytes are zero on both sides, so a plain compare would pass while the two relocations name different places. Masking anyway keeps one method for REL objects and for Mach-O, where the field carries the addend. The addends differ because the original object holds another table in .rodata before the switch table and the candidate object does not.

Why read the constants

This step exists because of a documented bug in another reconstruction project: a comparison replayed the target address into the relocation field, compared instruction bytes, and never checked the data at that address, so a source literal of 0.0 appeared exact against a target literal of 128.0 until 1,548 floating-point references were audited. The wrong-constant candidate is this fixture's version of that defect, and the table read is the audit. The count of five comes from the listing: a compare against 4 with an unsigned jump admits indexes 0 to 4, and the load reads 4 bytes per index.

What the tool's own compare can see

The comparison tool line-diffs provider text on eight dimensions, and its assembly dimension carries two fixed limitations: exact provider text is compared without address or generated-name normalization, and assembly is opaque provider text with relocation normalization unavailable. An unchanged assembly dimension means equal text from one engine, a changed one means different text, and neither is a statement about bytes. Two copies of the same code at different addresses diff as changed. The byte-level proof is the part the tool leaves to you.

Follow-ups

  1. L3SeniorWhy is the addend left out when the two relocation records are matched?

    Show expected answer

    the addend encodes where the table sits in that object's .rodata, which depends on what else the object holds, not on what the function does.

  2. L3SeniorWhat does a changed assembly dimension in the comparison tool tell you about the two functions' bytes?

    Show expected answer

    nothing; it is a text diff with addresses inside, and a relocatable object against its linked image diffs as changed.

  3. L4StaffTwo candidates with different source text pass every byte check. What have you proved?

    Show expected answer

    that this compiler folded both to the same code and data, not that either is the original text; signed overflow being undefined lets the compiler merge the two multiplies.

  4. L4StaffA candidate passes bytes and constants. Is behaviour settled?

    Show expected answer

    on the same architecture yes, since code and referenced data are equal; the trap cell still depends on the host that runs the grid, so the proof names it.

Wrong answers

Show the wrong answers that interviewers hear
  • “Equal size means equal function.”

    Size is a diagnostic; a candidate with the right length can differ in hundreds of bytes.

  • “A byte match recovers the source.”

    Different source text can compile to identical bytes; the match is a statement about one compiler and one set of flags.

  • “The comparison tool said unchanged, so the bytes match.”

    It compared decompiler text with addresses inside and says so in its own limitations.

Taught in

The rebuild lesson builds the masking, the record compare and the table read, the proof harness section records the eight candidates, and the comparison section states the assembly limitation.