Skip to content

Commit 0ed2840

Browse files
authored
boot_stage2: improve reproducibility (#1907)
Specifying the final boot2 source file as a link library here causes the final `.elf` to be linked directly with that `.S`, which causes it to be compiled into an object file with a name like `/tmp/<random chars>.o`. This temporary object name is embedded in the final `.elf`, so the `.elf`'s contents change after each link even if none of the input files change, breaking reproducibility. Fix the issue by specifying the source file as the source for an object-only library, then specifying the library's object files as the target link libraries, so the source is compiled in a separate step and only the object is passed to the linker.
1 parent ec0037b commit 0ed2840

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/rp2040/boot_stage2/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ function(pico_define_boot_stage2 NAME SOURCES)
6666
add_custom_command(OUTPUT ${ORIGINAL_BIN} DEPENDS ${NAME} COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${NAME}> ${ORIGINAL_BIN}
6767
VERBATIM)
6868

69-
add_custom_target(${NAME}_padded_checksummed_asm DEPENDS ${PADDED_CHECKSUMMED_ASM})
7069
add_custom_command(OUTPUT ${PADDED_CHECKSUMMED_ASM} DEPENDS ${ORIGINAL_BIN}
7170
COMMAND ${Python3_EXECUTABLE} ${PICO_BOOT_STAGE2_DIR}/pad_checksum -s 0xffffffff ${ORIGINAL_BIN} ${PADDED_CHECKSUMMED_ASM}
7271
VERBATIM)
7372

74-
add_library(${NAME}_library INTERFACE)
75-
add_dependencies(${NAME}_library ${NAME}_padded_checksummed_asm)
76-
# not strictly (or indeed actually) a link library, but this avoids dependency cycle
77-
target_link_libraries(${NAME}_library INTERFACE ${PADDED_CHECKSUMMED_ASM})
73+
add_library(${NAME}_library OBJECT ${PADDED_CHECKSUMMED_ASM})
74+
target_link_libraries(${NAME}_library INTERFACE "$<TARGET_OBJECTS:${NAME}_library>")
7875
target_link_libraries(${NAME}_library INTERFACE boot_stage2_headers)
7976

8077
list(GET SOURCES 0 FIRST_SOURCE)

src/rp2350/boot_stage2/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ function(pico_define_boot_stage2 NAME SOURCES)
6666
add_custom_command(OUTPUT ${ORIGINAL_BIN} DEPENDS ${NAME} COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${NAME}> ${ORIGINAL_BIN}
6767
VERBATIM)
6868

69-
add_custom_target(${NAME}_padded_checksummed_asm DEPENDS ${PADDED_CHECKSUMMED_ASM})
7069
add_custom_command(OUTPUT ${PADDED_CHECKSUMMED_ASM} DEPENDS ${ORIGINAL_BIN}
7170
COMMAND ${Python3_EXECUTABLE} ${PICO_BOOT_STAGE2_DIR}/pad_checksum -s 0xffffffff -a $<IF:${PICO_RISCV},riscv,arm> ${ORIGINAL_BIN} ${PADDED_CHECKSUMMED_ASM}
7271
VERBATIM)
7372

74-
add_library(${NAME}_library INTERFACE)
75-
add_dependencies(${NAME}_library ${NAME}_padded_checksummed_asm)
76-
# not strictly (or indeed actually) a link library, but this avoids dependency cycle
77-
target_link_libraries(${NAME}_library INTERFACE ${PADDED_CHECKSUMMED_ASM})
73+
add_library(${NAME}_library OBJECT ${PADDED_CHECKSUMMED_ASM})
74+
target_link_libraries(${NAME}_library INTERFACE "$<TARGET_OBJECTS:${NAME}_library>")
7875
target_link_libraries(${NAME}_library INTERFACE boot_stage2_headers)
7976

8077
list(GET SOURCES 0 FIRST_SOURCE)

0 commit comments

Comments
 (0)