Project Stage 1: Troubleshooting a bit - Coming soon
Procedure for Troubleshooting
Debugging using the following method:
First Error Analysis: I carefully reviewed the error logs after my initial build attempt failed.
./pass-instances.def:47:23: error: expected ';' at end of member declaration 47 | NEXT_PASS_WITH_ARG (pass_mypass, 1, 1)
This suggested an issue with my pass registration syntax.
Examining Pass Declaration Conventions: I ran the following to examine the passes that were already included in the GCC source code:
cd ~/git/gcc/gcc grep -r "NEXT_PASS" passes.def
This showed that NEXT_PASS (pass_name, number) was the proper format instead of NEXT_PASS_WITH_ARG.
Function name Pattern Analysis: I looked at various pass implementations to learn more about the name conventions:
cd ~/git/gcc/gcc find . -name "tree-*.cc" | xargs grep "make_pass_"
This demonstrated to me that the pattern make_pass_X, where X is the pass name without the "pass_" prefix, is what GCC wants factory functions to adhere to.
Investigating Makefile Formatting: I looked at both the original and my edited version to comprehend the Makefile formatting problem:
cd ~/git/gcc/gcc grep -A 10 -B 10 "OBJS" Makefile.in > original_makefile_section.txt # After comparing my changes with the original format
This showed me that I needed to put a backslash at the end of my object file entry and keep the exact same indentation (using tabs).
Rebuilding with Verbose Output: In order to pinpoint the precise location of the build's failure, I tried rebuilding using more verbose output:
cd ~/gcc-build-001 make V=1 -j 4 |& tee verbose_build.log
Provided more detailed error information: issue was with the pass registration syntax.
Isolating Components: To narrow down the issue, I tried building just the compiler component:
cd ~/gcc-build-001/gcc make -j 1 |& tee gcc_build.log
This made the error messages easier to identify and address.
Comparing with Reference Implementations: I studied successful GCC pass implementations:
cd ~/git/gcc/gcc # Example: Looking at tree-ssa-pre.cc as a reference less tree-ssa-pre.cc
Helped me in understanding the correct structure and naming conventions for GCC passes.
Version-Specific Documentation: Just to be sure: checked if there were version-specific requirements for the GCC version I was working with:
cd ~/git/gcc git log -1 --pretty=format:"%h %s" # To identify the specific GCC version
Specific Troubleshooting
Naming Convention Inconsistencies: My initial implementation used inconsistent naming:
// In tree-my-pass.cc gimple_opt_pass *make_tree_my_pass(gcc::context *ctxt) // In tree-pass.h declaration extern gimple_opt_pass *make_tree_my_pass(gcc::context *ctxt); // In passes.def NEXT_PASS (pass_my_pass, 1)
I later discovered GCC requires a specific pattern:
Factory function must be named
make_pass_X
Pass registration must use
pass_X
These names must be consistent across all files
Makefile Syntax Errors: The error message
missing separator (did you mean TAB instead of 8 spaces?)
occurred because:# I initially added: tree_my_pass.o \ # With spaces instead of tabs # Should have been: [TAB]tree-my-pass.o \ # With a tab character for indentation
I confirmed this by examining the exact whitespace characters in the Makefile:
cat -A Makefile.in | grep -A 3 -B 3 "tree-my-pass"
This showed spaces (represented as
^I
) instead of tabs where required.Pass Registration Syntax Error: When I tried using
NEXT_PASS_WITH_ARG
, I encountered compilation errors because:# I tried: NEXT_PASS_WITH_ARG (pass_my_pass, 1, 1) NEXT_PASS_WITH_ARG (pass_my_pass, 0) # But examining other passes showed I should use: NEXT_PASS (pass_my_pass, 1)
I discovered through source investigation that
NEXT_PASS_WITH_ARG
is used differently in the GCC codebase than I initially understood.Header Inclusion Order: I found that the order of header inclusions could affect compilation:
// Original order #include "tree.h" #include "gimple.h" #include "tree-pass.h" // After examining compiler warnings, I tried: #include "tree-pass.h" #include "tree.h" #include "gimple.h"
Comments
Post a Comment