@@ -89,10 +89,11 @@ StatusOr<Section> ObjdumpSectionNameToAddr(const std::string& path,
8989 return section;
9090}
9191
92- StatusOr<int64_t > NmSymbolNameToAddr (const std::string& path, const std::string& symbol_name) {
92+ StatusOr<int64_t > NmSymbolNameToAddr (const std::string& nm_output_path,
93+ const std::string& symbol_name) {
9394 // Extract the address from nm as the gold standard.
9495 int64_t symbol_addr = -1 ;
95- std::string nm_out = px::Exec ( absl::StrCat ( " nm " , path)). ValueOrDie ( );
96+ PX_ASSIGN_OR_RETURN ( auto nm_out, px::ReadFileToString (nm_output_path) );
9697 std::vector<absl::string_view> nm_out_lines = absl::StrSplit (nm_out, ' \n ' );
9798 for (auto & line : nm_out_lines) {
9899 if (line.find (symbol_name) != std::string::npos) {
@@ -163,8 +164,9 @@ TEST(ElfReaderTest, ListFuncSymbolsSuffixMatch) {
163164
164165TEST (ElfReaderTest, SymbolAddress) {
165166 const std::string path = kTestExeFixture .Path ().string ();
167+ const std::string nm_output_path = kTestExeFixture .NmOutputPath ().string ();
166168 const std::string kSymbolName = " CanYouFindThis" ;
167- ASSERT_OK_AND_ASSIGN (const int64_t symbol_addr, NmSymbolNameToAddr (path , kSymbolName ));
169+ ASSERT_OK_AND_ASSIGN (const int64_t symbol_addr, NmSymbolNameToAddr (nm_output_path , kSymbolName ));
168170
169171 // Actual tests of SymbolAddress begins here.
170172
@@ -195,8 +197,9 @@ TEST(ElfReaderTest, VirtualAddrToBinaryAddr) {
195197
196198TEST (ElfReaderTest, AddrToSymbol) {
197199 const std::string path = kTestExeFixture .Path ().string ();
200+ const std::string nm_output_path = kTestExeFixture .NmOutputPath ().string ();
198201 const std::string kSymbolName = " CanYouFindThis" ;
199- ASSERT_OK_AND_ASSIGN (const int64_t symbol_addr, NmSymbolNameToAddr (path , kSymbolName ));
202+ ASSERT_OK_AND_ASSIGN (const int64_t symbol_addr, NmSymbolNameToAddr (nm_output_path , kSymbolName ));
200203
201204 ASSERT_OK_AND_ASSIGN (std::unique_ptr<ElfReader> elf_reader, ElfReader::Create (path));
202205
@@ -216,8 +219,9 @@ TEST(ElfReaderTest, AddrToSymbol) {
216219
217220TEST (ElfReaderTest, InstrAddrToSymbol) {
218221 const std::string path = kTestExeFixture .Path ().string ();
222+ const std::string nm_output_path = kTestExeFixture .NmOutputPath ().string ();
219223 const std::string kSymbolName = " CanYouFindThis" ;
220- ASSERT_OK_AND_ASSIGN (const int64_t kSymbolAddr , NmSymbolNameToAddr (path , kSymbolName ));
224+ ASSERT_OK_AND_ASSIGN (const int64_t kSymbolAddr , NmSymbolNameToAddr (nm_output_path , kSymbolName ));
221225
222226 ASSERT_OK_AND_ASSIGN (std::unique_ptr<ElfReader> elf_reader, ElfReader::Create (path));
223227
@@ -300,12 +304,15 @@ TEST(ElfReaderTest, FuncByteCode) {
300304TEST (ElfReaderTest, GolangAppRuntimeBuildVersion) {
301305 const std::string kPath =
302306 px::testing::BazelRunfilePath (" src/stirling/obj_tools/testdata/go/test_go_1_19_binary" );
307+ const std::string kGoBinNmOutput =
308+ px::testing::BazelRunfilePath (" src/stirling/obj_tools/testdata/go/test_go_1_19_nm_output" );
303309 ASSERT_OK_AND_ASSIGN (std::unique_ptr<ElfReader> elf_reader, ElfReader::Create (kPath ));
304310 ASSERT_OK_AND_ASSIGN (ElfReader::SymbolInfo symbol,
305311 elf_reader->SearchTheOnlySymbol (" runtime.buildVersion" ));
306312// Coverage build might alter the resultant binary.
307313#ifndef PL_COVERAGE
308- ASSERT_OK_AND_ASSIGN (auto expected_addr, NmSymbolNameToAddr (kPath , " runtime.buildVersion" ));
314+ ASSERT_OK_AND_ASSIGN (auto expected_addr,
315+ NmSymbolNameToAddr (kGoBinNmOutput , " runtime.buildVersion" ));
309316 EXPECT_EQ (symbol.address , expected_addr);
310317#endif
311318 EXPECT_EQ (symbol.size , 16 ) << " Symbol table entry size should be 16" ;
0 commit comments