Paths in Pieces
This technical analysis explains why standard binary auditing tools fail to detect absolute paths in C++ binaries compiled with modern GCC versions. The compiler optimizes string handling by vectorizing data, which obscures the original file paths from simple string-searching utilities.
Why it matters
Understanding these compiler optimizations is critical for developers and security researchers who rely on binary analysis for debugging and auditing software distribution.
Many [1] [2] [3] [4] [5] [6] [7] [8] [9] Linux distributions and package managers audit just-built binaries for non-relocatable absolute paths. If a binary contains a path /path/from/build/machine , it might not run on the end-user's machine.
Now, a basic grep on the binary, or a slightly more sophisticated
$ strings bin/app | grep /path/from/build/machine using GNU binutils's strings will detect these paths, right?
The answer is no , at least when using GCC and targeting x86-64 : you should not assume that string constants end up literally in the binary.
In this C++ source we create a std::string from a string constant:
#include <iostream> #include <string> #define PREFIX "/home/linuxbrew/.linuxbrew" int main() { std::string prefix{PREFIX}; std::cout << prefix << '\n'; } Compile with GCC 12 or later and run, which prints the path:
Get smarter about the news
Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.
Create free accountAlready have an account? Sign in