From 2a55eb0a48f93d64b13c15a077ecc1fb6e00187b Mon Sep 17 00:00:00 2001 From: Aetias Date: Tue, 2 Jul 2024 10:31:33 +0200 Subject: [PATCH] Ignore `KILL` macros inside line comments --- tools/elf/elfkill.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/elf/elfkill.cpp b/tools/elf/elfkill.cpp index da4d77d1..d86d378d 100644 --- a/tools/elf/elfkill.cpp +++ b/tools/elf/elfkill.cpp @@ -128,7 +128,7 @@ bool GetFunctionSymbols(const elfio &elf, std::vector &outSymbols) { if (symbol.name.find("@", 0) == 0) continue; if (symbol.name.find("$", 0) == 0) continue; if (symbol.name.find(".", 0) == 0) continue; - if (symbol.section.name != ".text") continue; + if (symbol.section.name != ".text" && symbol.section.name != ".data") continue; symbols.push_back(symbol); } @@ -141,6 +141,7 @@ bool FindSymbolsToKill(const char *srcFile, std::unordered_set &out std::ifstream file(srcFile); const std::string killMacro = "KILL("; + const std::string lineComment = "//"; std::string line; size_t row = 0; std::unordered_set symbolsToKill; @@ -150,6 +151,9 @@ bool FindSymbolsToKill(const char *srcFile, std::unordered_set &out while (true) { size_t macroOffset = line.find(killMacro, endOffset); if (macroOffset == std::string::npos) break; + + size_t commentOffset = line.find(lineComment, endOffset); + if (macroOffset > commentOffset) break; size_t symbolOffset = macroOffset + killMacro.length(); symbolOffset = line.find_first_not_of(" \t", symbolOffset);