The GCC driver simplifies `find_a_program` and `find_a_file` functions
GCC refactors its driver code by streamlining file and program lookup functions, removing redundant parameters and logic.
This commit simplifies the find_a_program and find_a_file functions within the GCC driver. Previously, these functions shared a common mode parameter for access checks, but it was found that find_a_file always performed a read check (R_OK) and find_a_program always performed an execute check (X_OK). By removing this redundant parameter and other dead code, the driver’s codebase becomes cleaner and easier to maintain. This clarifies the intent of each function.
In Details
The GCC driver's find_a_program and find_a_file functions, located primarily in gcc.cc, are responsible for locating executables and other files needed during the compilation process. This commit refactors these functions after their separation, removing the generic mode parameter. find_a_file now implicitly uses R_OK (read-only access check), while find_a_program implicitly uses X_OK (execute access check). This elimination of unused parameters and related logic simplifies the internal API and reduces code duplication, improving maintainability within the driver component.
For Context
When you use GCC to compile a program, the compiler driver acts like a conductor, orchestrating various tools and files to get the job done. This includes finding programs like the assembler or linker, and locating necessary files like header files. Inside the GCC's code, there are functions like find_a_program and find_a_file that do this searching. Initially, they had a common setting to check if a file could be read, written, or executed. However, it turned out that find_a_file always just checks if it can read a file, and find_a_program always checks if it can execute a program. This change simplifies these routines by removing the unnecessary common setting and making them more specialized, which makes the compiler's internal code cleaner and easier for developers to understand and modify.