-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: long dependency paths can break compiler driver #26261
Comments
This relates to using Chapel with E4S. I was testing out using Chapel with E4S on my Mac (I recommend homebrew if using Chapel on a Mac is your main goal).
|
This happens when the second driver phase is reading a string from a file saved by the first driver phase, for inter-phase communication. The max length of string it will read is hardcoded above at 4096. There's no good reason I know of for this value; I recall picking it because I saw a similar hardcoded limit elsewhere in the compiler for things like path lengths, but I can't find such a limit now so I don't know where I got that from. Potential solutions Ahmad and I discussed:
(1) is simpler but hardcoding still doesn't feel great, and using too large a value means wasting (a small amount of) memory. (2) would be fully future-proof but it also feels bad to add something that complex to accomplish this. |
Can this just be solved by reading into a more dynamic buffer like std::string readLine(FILE* file) {
std::string line;
char buffer[4096];
while(fgets(buffer, sizeof(buffer), file)) {
line += buffer;
// if line ends in newline, trim it and break
// if eof, break
}
return line;
} This isn't the most optimal, but it avoids hardcoding a max buffer size and is simple |
Yeah we could, and that's probably the best solution. I had ruled it out a while ago since I thought reading an unlimited amount from a file pointer isn't a good practice, but that might be unfounded. As long as we still don't enable buffer overflows, I think the worst that could happen would be looping for a long time and eventually hiting OOM rather than erroring immediately. |
See related #8757 -- I think |
PR'd #26310 to fix this |
Unfortunately while testing the fix, I found that it works for the driver string length limit, but we then immediately run into uses of For instance, on my Mac I ran the driver in lldb, and between phases changed the main module path (stored in a file) to an 8000 character path. It got past restoring the string, but quickly hit this assert, where the size of So the driver's was just the first length limit encountered, but to actually function with really long paths we'll need to fix all instances of hardcoded length limits (#8757). Will go ahead and do that |
Summary of Problem
If chapel dependencies have very long paths, the compiler driver can break.
Description:
This seems to happen mostly with spack dependencies since spack encodes shasums in the package path. The most likely culprits are the
CHPL_TARGET_BUNDLED_LINK_ARGS
orCHPL_TARGET_BUNDLED_COMPILE_ARGS
, but any of the flags that accumulate values longer than4096
chars can cause this problem.Is this issue currently blocking your progress?
No, can be worked around by passing
--no-compiler-driver
tochpl
Steps to Reproduce
CHPL_TARGET_BUNDLED_COMPILE_ARGS
orCHPL_TARGET_BUNDLED_LINK_ARGS
as viewed fromprintchplenv --internal
is longer than 4096 chars.compiler/util/files.cpp:209
,assert(strBuf[len - 1] == '\n' && "stored line exceeds maximum length");
will fail.Source Code:
Compile command:
chpl foo.chpl
Execution command:
n/a, compilation fails
The text was updated successfully, but these errors were encountered: