Skip to content

Commit 829f258

Browse files
authored
benchmark: Build drivers with N_AST symtab entries (for debugging) (#30777)
On Darwin, we pass the *.swiftmodule paths transitively referenced by the driver executable to ld64. ld64 inserts N_AST references to these modules into the program, for later use by lldb. This change should let us exercise much more lldb functionality via `stepper` testing.
1 parent a87369b commit 829f258

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ macro(configure_sdks)
166166
endif()
167167
endmacro()
168168

169-
function (add_swift_benchmark_library objfile_out sibfile_out)
169+
function (add_swift_benchmark_library objfile_out sibfile_out swiftmodule_out)
170170
cmake_parse_arguments(BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS;DEPENDS" ${ARGN})
171171

172172
precondition(BENCHLIB_MODULE_PATH)
@@ -197,6 +197,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
197197
"-o" "${objfile}"
198198
${sources})
199199
set(${objfile_out} "${objfile}" PARENT_SCOPE)
200+
set(${swiftmodule_out} "${swiftmodule}" PARENT_SCOPE)
200201

201202
if(SWIFT_BENCHMARK_EMIT_SIB)
202203
precondition(sibfile_out)
@@ -401,19 +402,21 @@ function (swift_benchmark_compile_archopts)
401402
endif()
402403
set(bench_library_objects)
403404
set(bench_library_sibfiles)
405+
set(bench_library_swiftmodules)
404406
set(opt_view_dirs)
405407
# Build libraries used by the driver and benchmarks.
406408
foreach(module_name_path ${BENCH_LIBRARY_MODULES})
407409
set(sources "${srcdir}/${module_name_path}.swift")
408410

409-
add_swift_benchmark_library(objfile_out sibfile_out
411+
add_swift_benchmark_library(objfile_out sibfile_out swiftmodule_out
410412
MODULE_PATH "${module_name_path}"
411413
SOURCE_DIR "${srcdir}"
412414
OBJECT_DIR "${objdir}"
413415
SOURCES ${sources}
414416
LIBRARY_FLAGS ${common_swift4_options})
415417
precondition(objfile_out)
416418
list(APPEND bench_library_objects "${objfile_out}")
419+
list(APPEND bench_library_swiftmodules "${swiftmodule_out}")
417420
if (SWIFT_BENCHMARK_EMIT_SIB)
418421
precondition(sibfile_out)
419422
list(APPEND bench_library_sibfiles "${sibfile_out}")
@@ -433,7 +436,7 @@ function (swift_benchmark_compile_archopts)
433436

434437
set(objfile_out)
435438
set(sibfile_out)
436-
add_swift_benchmark_library(objfile_out sibfile_out
439+
add_swift_benchmark_library(objfile_out sibfile_out swiftmodule_out
437440
MODULE_PATH "${module_name_path}"
438441
SOURCE_DIR "${srcdir}"
439442
OBJECT_DIR "${objdir}"
@@ -442,6 +445,7 @@ function (swift_benchmark_compile_archopts)
442445
DEPENDS ${bench_library_objects})
443446
precondition(objfile_out)
444447
list(APPEND bench_driver_objects "${objfile_out}")
448+
list(APPEND bench_library_swiftmodules "${swiftmodule_out}")
445449
if (SWIFT_BENCHMARK_EMIT_SIB)
446450
precondition(sibfile_out)
447451
list(APPEND bench_driver_sibfiles "${sibfile_out}")
@@ -464,6 +468,7 @@ function (swift_benchmark_compile_archopts)
464468
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
465469
set(source "${srcdir}/${module_name_path}.swift")
466470
list(APPEND SWIFT_BENCH_OBJFILES "${objfile}")
471+
list(APPEND bench_library_swiftmodules "${swiftmodule}")
467472

468473
if ("${bench_flags}" MATCHES "-whole-module.*")
469474
set(output_option "-o" "${objfile}")
@@ -622,6 +627,15 @@ function (swift_benchmark_compile_archopts)
622627
else()
623628
set(SWIFT_LINK_RPATH "${SWIFT_RPATH_BASE}/${BENCH_COMPILE_ARCHOPTS_PLATFORM}")
624629
endif()
630+
631+
# On Darwin, we pass the *.swiftmodule paths transitively referenced by the
632+
# driver executable to ld64. ld64 inserts N_AST references to these modules
633+
# into the program, for later use by lldb.
634+
set(ld64_add_ast_path_opts)
635+
foreach(ast_path ${bench_library_swiftmodules})
636+
list(APPEND ld64_add_ast_path_opts "-Wl,-add_ast_path,${ast_path}")
637+
endforeach()
638+
625639
add_custom_command(
626640
OUTPUT "${OUTPUT_EXEC}"
627641
DEPENDS
@@ -647,6 +661,7 @@ function (swift_benchmark_compile_archopts)
647661
"-Xlinker" "${SWIFT_LINK_RPATH}"
648662
${bench_library_objects}
649663
${bench_driver_objects}
664+
${ld64_add_ast_path_opts}
650665
${SWIFT_BENCH_OBJFILES}
651666
${objcfile}
652667
"-o" "${OUTPUT_EXEC}"

0 commit comments

Comments
 (0)