ilasm -OUTPUT parameter does not handle long paths well on Unix
I'm finally looking into adopting the CoreCLR version of ilasm for use in corefx (building our one .ilproj file there). Everything works okay on the Windows version, but I'm seeing that the Unix ilasm does not work correctly if the path it is passed to -OUTPUT is too long. Here's a sample command that does not work:
/home/eric/corefx/Tools/ilasm/ilasm -QUIET -DLL -INCLUDE=include/netstandard -KEY=/home/eric/corefx/Tools/MSFT.snk System.Runtime.CompilerServices.Unsafe.il -OUTPUT:/home/eric/corefx/bin/obj/AnyOS.AnyCPU.Debug/System.Runtime.CompilerServices.Unsafe/netstandard/System.Runtime.CompilerServices.Unsafe.dll
Error : Invalid Option: -OUTPUT:/home/eric/corefx/bin/obj/AnyOS.AnyCPU.Debug/System.Runtime.CompilerServices.Unsafe/netstandard/System.Runtime.CompilerServices.Unsafe.dll
Usage: ilasm [Options] <sourcefile> [Options]
... <cut>
Here's a command that does work:
/home/eric/corefx/Tools/ilasm/ilasm -QUIET -DLL -INCLUDE=include/netstandard -KEY=/home/eric/corefx/Tools/MSFT.snk System.Runtime.CompilerServices.Unsafe.il -OUTPUT:/home/eric/corefx/bin/System.Runtime.CompilerServices.Unsafe.dll
I just chopped a bunch of characters from the middle of the output path. This seems broken to me, but is there possibly something else that I'm doing wrong?
@adiaaida Any ideas?
According to my experiments, it starts failing if the OUTPUT parameter is 121 characters or longer. With 120 characters, it works fine.
I'd have to look into it. My familiarity with ilasm is actually pretty minimal. @RussKeldorph Any thoughts?
@adiaaida @mellinoe No idea, but smells like a MultiByteToWideChar (or vice versa) bytecount bug (2 * 121 is approaching _MAX_PATH). We should at least get this to support _MAX_PATH, which I assume it does on Windows, but if it's easy we should remove Windows-specific path limits on other platforms while we're at it.
@mellinoe It appears to be a bit simpler than I thought. Easy fix to bump it up arbitrarily. A more elegant fix that defers to platform limits is more involved, obviously.
@RussKeldorph I see, so we're essentially hard-limited to 128 characters right now? That makes sense if you count the extra 8 characters from -OUTPUT:, as well.
I verified that simply changing that line to char szOpt[1024]; fixes the problem (or at least raises the limit to something more reasonable). Is that an acceptable short-term fix that I could submit?
@mellinoe maybe good enough to close this
It seems issue has been fixed in dotnet/coreclr#9782.
No, this simply increased the limit to an arbitrary number. Ideally, we would remove this arbitrary limit and simply defer to any length limits on the local system. I think that the argument processing only ever looks at the first three characters of an option, so there seems to be little reason to keep a large buffer in this case, though I could be missing something.