From ef94361ab43c91a45a2999c00b3d0d6804ab08c4 Mon Sep 17 00:00:00 2001 From: Bill Yang Date: Thu, 23 May 2024 11:53:13 -0700 Subject: [PATCH] ignore debug symbols --- .../inject_hash/macho_parser/macho_parser.c | 14 ++++++++++++++ .../inject_hash/tests/test_libs/CMakeLists.txt | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/util/fipstools/inject_hash/macho_parser/macho_parser.c b/util/fipstools/inject_hash/macho_parser/macho_parser.c index 5f7f061a9c8..eed151a0c3d 100644 --- a/util/fipstools/inject_hash/macho_parser/macho_parser.c +++ b/util/fipstools/inject_hash/macho_parser/macho_parser.c @@ -191,6 +191,20 @@ int find_macho_symbol_index(uint8_t *symbol_table_data, size_t symbol_table_size int found = 0; for (size_t i = 0; i < symbol_table_size / sizeof(struct nlist_64); i++) { struct nlist_64 *symbol = (struct nlist_64 *)(symbol_table_data + i * sizeof(struct nlist_64)); + + // Skip debugging symbols + // + // #define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */ + // + // "Only symbolic debugging entries have some of the N_STAB bits set and if any of these bits are set then it is + // a symbolic debugging entry (a stab). In which case then the values of the n_type field (the entire field) + // are given in " + // + // https://github.com/apple-oss-distributions/xnu/blob/main/EXTERNAL_HEADERS/mach-o/nlist.h + if (symbol->n_type & N_STAB) { + continue; + } + if (strcmp(symbol_name, &string_table[symbol->n_un.n_strx]) == 0) { if (found == 0) { *index = symbol->n_value; diff --git a/util/fipstools/inject_hash/tests/test_libs/CMakeLists.txt b/util/fipstools/inject_hash/tests/test_libs/CMakeLists.txt index b47430ec515..f253dc75bfd 100644 --- a/util/fipstools/inject_hash/tests/test_libs/CMakeLists.txt +++ b/util/fipstools/inject_hash/tests/test_libs/CMakeLists.txt @@ -2,7 +2,6 @@ if(FIPS AND APPLE) set(INJECT_HASH_TEST_LIB_COMPILE_OPTIONS "-Wno-unused-function" "-Wno-missing-prototypes" - "-g0" ) function(create_test_lib name)