-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix as.exe
crash on Windows
#20
Conversation
Doesn't crash, but no longer finds the wide-char filenames... search continues. |
221c870
to
df9ddb1
Compare
Better option than porting getopt to Windows
Windows doesn't build yet, Unix side works.
wide string conversion is... broken. Wide characters and wide strings are evil
...at least if we don't touch wide strings. The code added in previous commits to cope with narrow vs wide strings is left in place, "just in case". Both Unix and Windows builds effectively use narrow strings, though.
src/gas/process.posix.cc
Outdated
// and the warning generated by -Wdangling-gsl was effectively non-actionable: | ||
// warning: object backing the pointer will be destroyed at the end of the full-expression | ||
// | ||
const char *const epath = executable_path.string ().c_str (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually worries me; the "full expression" is this entire line, so once executable_path.string().c_str()
has finished evaluation, it is potentially invalidated, meaning that epath
may be garbage.
I think it would be safer -- and would also fix the -Wdangling-gsl
warning -- if you instead did auto path = executable_path.string()
, and then everywhere you had epath
you instead used path.c_str()
. Then we know the value returned from .c_str()
won't be destructed until path
is destructed, which is at end of scope, vs "end of the full expression".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means code duplication and doesn't really change anything though... It's a cosmetic change with no real effect - the temporary is still removed and we still duplicate the C string we get from the temporary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that's later. My recollection is that this full expression is basically:
auto __tmp = executable_path.string();
const char *const epath = __tmp.c_str();
which looks fine, except for the all important question: when is __tmp
destructed? At various points in time this was up to the compiler, and some compilers would destruct __tmp
at end of enclosing scope (i.e. "you're fine") and some would destruct __tmp
at end of expression, i.e.:
const char *const epath;
{ auto __tmp = executable_path.string();
epath = __tmp.c_str();
/* __tmp destructed at end of full expression */ }
/* `epath` now pointing to garbage */
Perhaps the semantics have since been standardized, but at least in C++98 this was not well specified, and different compilers would do different things. The warning is trying to warn you about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The local object is strictly destroyed when it leaves its scope, in this case the function.
return s; | ||
#else | ||
std::string ret (s.length (), 0); | ||
std::transform ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused wrt how this actually transforms to UTF-8 on Windows, when platform::string
is std::wstring
. This looks like it'll just truncate wchar_t
to char
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
platform::string
is now uniformly std::string
, I stopped using wstring
but kept the abstraction "just in case"
Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.1.1 Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.1.2 Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.2.1 Changes: dotnet/android-native-tools@L_17.0.6-7.1.0...L_17.0.6-7.1.1 Changes: dotnet/android-native-tools@L_17.0.6-7.1.1...L_17.0.6-7.1.2 Changes: dotnet/android-native-tools@L_17.0.6-7.1.2...L_17.0.6-7.2.0 Changes: dotnet/android-native-tools@L_17.0.6-7.2.0...L_17.0.6-7.2.1 This release makes changes to how we build and run the `as.exe` wrapper, so that it can be verified by API Scan without any issues. Otherwise it is identical to the previous release, using the same version of LLVM. * [ci] Build and sign in a DevDiv pipeline by @pjcollins in dotnet/android-native-tools#7 * [ci] Migrate to the 1ES template by @pjcollins in dotnet/android-native-tools#8 * [ci] Improve binskim scan performance by @pjcollins in dotnet/android-native-tools#11 * [ci] Improve triggers and support test signing by @pjcollins in dotnet/android-native-tools#12 * [ci] Fix unsigned artifact uploading by @pjcollins in dotnet/android-native-tools#13 * [ci] Disable automatic GitHub action trigger by @pjcollins in dotnet/android-native-tools#16 * [ci] Build on performance build pools by @pjcollins in dotnet/android-native-tools#15 * Build `as.exe` on windows by @grendello in dotnet/android-native-tools#10 * [ci] Add API Scan job by @pjcollins in dotnet/android-native-tools#9 * Fix `as.exe` crash on Windows by @grendello in dotnet/android-native-tools#20 * [ci] Use managed identity for API Scan by @pjcollins in dotnet/android-native-tools#21 * Back to wide strings on Windows + magic encantations by @grendello in dotnet/android-native-tools#22
Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.1.1 Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.1.2 Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.2.1 Changes: dotnet/android-native-tools@L_17.0.6-7.1.0...L_17.0.6-7.1.1 Changes: dotnet/android-native-tools@L_17.0.6-7.1.1...L_17.0.6-7.1.2 Changes: dotnet/android-native-tools@L_17.0.6-7.1.2...L_17.0.6-7.2.0 Changes: dotnet/android-native-tools@L_17.0.6-7.2.0...L_17.0.6-7.2.1 This release makes changes to how we build and run the `as.exe` wrapper, so that it can be verified by API Scan without any issues. Otherwise it is identical to the previous release, using the same version of LLVM. * [ci] Build and sign in a DevDiv pipeline by @pjcollins in dotnet/android-native-tools#7 * [ci] Migrate to the 1ES template by @pjcollins in dotnet/android-native-tools#8 * [ci] Improve binskim scan performance by @pjcollins in dotnet/android-native-tools#11 * [ci] Improve triggers and support test signing by @pjcollins in dotnet/android-native-tools#12 * [ci] Fix unsigned artifact uploading by @pjcollins in dotnet/android-native-tools#13 * [ci] Disable automatic GitHub action trigger by @pjcollins in dotnet/android-native-tools#16 * [ci] Build on performance build pools by @pjcollins in dotnet/android-native-tools#15 * Build `as.exe` on windows by @grendello in dotnet/android-native-tools#10 * [ci] Add API Scan job by @pjcollins in dotnet/android-native-tools#9 * Fix `as.exe` crash on Windows by @grendello in dotnet/android-native-tools#20 * [ci] Use managed identity for API Scan by @pjcollins in dotnet/android-native-tools#21 * Back to wide strings on Windows + magic encantations by @grendello in dotnet/android-native-tools#22
Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.1.1 Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.1.2 Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.2.1 Context: https://github.com/xamarin/xamarin-android-binutils/releases/tag/L_17.0.6-7.2.2 Changes: dotnet/android-native-tools@L_17.0.6-7.1.0...L_17.0.6-7.1.1 Changes: dotnet/android-native-tools@L_17.0.6-7.1.1...L_17.0.6-7.1.2 Changes: dotnet/android-native-tools@L_17.0.6-7.1.2...L_17.0.6-7.2.0 Changes: dotnet/android-native-tools@L_17.0.6-7.2.0...L_17.0.6-7.2.1 Changes: dotnet/android-native-tools@L_17.0.6-7.2.1...L_17.0.6-7.2.2 This release makes changes to how we build and run the `as.exe` wrapper, so that it can be verified by API Scan without any issues. Otherwise it is identical to the previous release, using the same version of LLVM. * [ci] Build and sign in a DevDiv pipeline by @pjcollins in dotnet/android-native-tools#7 * [ci] Migrate to the 1ES template by @pjcollins in dotnet/android-native-tools#8 * [ci] Improve binskim scan performance by @pjcollins in dotnet/android-native-tools#11 * [ci] Improve triggers and support test signing by @pjcollins in dotnet/android-native-tools#12 * [ci] Fix unsigned artifact uploading by @pjcollins in dotnet/android-native-tools#13 * [ci] Disable automatic GitHub action trigger by @pjcollins in dotnet/android-native-tools#16 * [ci] Build on performance build pools by @pjcollins in dotnet/android-native-tools#15 * Build `as.exe` on windows by @grendello in dotnet/android-native-tools#10 * [ci] Add API Scan job by @pjcollins in dotnet/android-native-tools#9 * Fix `as.exe` crash on Windows by @grendello in dotnet/android-native-tools#20 * [ci] Use managed identity for API Scan by @pjcollins in dotnet/android-native-tools#21 * Back to wide strings on Windows + magic encantations by @grendello in dotnet/android-native-tools#22
Code previously used to convert command-line arguments from wide encoding to UTF-8
we used when
as.exe
was built with MinGW, is no longer necessary. It was causingthe app to crash on Windows.