Oh boi oh boi oh boi,
this is just great. I faintly remembered using nsis at work once and thought I might give it a go again.
Innocently, I check out the svn on my debian-linux type computer, install mingw and compile this stuff. Had to read through the scons files to figure out the names of the targets but what gives?
Once I am through with that, I take a look https://nsis.sourceforge.io/Simple_tutorials and try out some programs to run on my windows virtual machine. To my surprise, windows says "not a valid win32 application" to "The bare minimum" and "Simple hello world - popup box". I am taken aback, I am flabbergasted. I search the bugs for something similar and find
https://sourceforge.net/p/nsis/bugs/1131/
While this is quite old, I think to myself that maybe the reloc sections are to blame. I recompile this stuff with -Wl,--disable-reloc-section and it actually works. I search through the debian repos and find a bunch of packages (like win32-loader) that claim to be built by nsis > 3.0, but with relocations enabled and what's better yet, they too work on a vm. This got me thinking. In lieu of a minimal working example, I look around and find https://github.com/NSIS-Dev/Examples There we have some files that I try that also work with relocations enabled. The one line that I couldn't change though was
"Page components"
otherwise windows didn't think of it as a valid win32 application.
So there you have it, on NSIS 3.08 compiled with mingw-w64 gcc 10 with .reloc enabled, there is some alignment?/sizing? issue that causes win xp/7/8.1 to reject the pe file if it doesn't have a "Page components" part, like your tutorial for example.
So much shade in an otherwise very detailed bug report. I just have to ask if you created the user especially for this report. I need to know.
Yeah, I kinda did.
Didn't mean anything by it though. I am grateful to all the cool people that make software like this possible. I have once tried contributing to some linux desktop environment and they treated me rather patronizingly, so whenever I file a bug report, I get flashbacks and just pour it all out.
Can you reproduce the issue and is there something I forgot to mention?
I have done that before. Easy to get mad at the world when you don't feel appreciated and easy to not feel appreciated in open-source.
I haven't tried to reproduce, but I'm sure Anders will. It makes sense. Something about relocations and our resource editor that adds the components dialog. I do believe the resource editor doesn't do relocations. So maybe the components page adds too much data and causes the section to grow. That would require to move relocations which it doesn't do. The end suggestion would probably be disabling relocations. But let's wait for Anders to confirm. He knows far better what's going on in these days.
I hope you get help with your addiction :)
I don't think I have touched that part of the PE that deals with the pages.
Last edit: Anders 2022-06-05
In that case I'm going to stick with the no reloc suggestion. Our code edits the PE a lot and doesn't handle relocs at all.
I recently ran into this issue with a project that I work on and it would be nice for NSIS to be able to handle having .reloc sections in the stubs in creates. Alternatively NSIS needs to default compile without .reloc sections.
Since binutils 2.36, ld will include a .reloc section by default when linking. Compiling NSIS with said binutils version required modifying SConstruct in order to pass
-Wl,--disable-reloc-sectionto the stubs environment. It appears thatAPPEND_LINKFLAGSis not being passed through.The stub environment flags are set in "./SCons/Config/gnu", add this line and see if this works:
stub_env.Append(LINKFLAGS = ['-Wl,--disable-reloc-section'])I added this flag, please report back if it works.
I checked the patch, but using 'CheckLinkFlag()' doesn't work, it returns 'no' when it should return 'yes'. This happens for both --disable-reloc-section and --enable-reloc-section.
Maybe 'CheckLinkFlag()' is not checking it correctly? Or maybe mingw-w64 doesn't throw an error for this linker option, ie is a "one way" flag.
I added the line I wrote earlier that force adds the flag, and that does work. But it's probably not what we want.
Older GCC cannot handle this flag so we need the check. Check the config.log file to see what is happening during the test. I tweaked CheckLinkFlag code a bit to make it work for me (to get anything other than no for even known good flags). And I deleted the scons folder and .db between testing runs...
I checked the log, and got an error about an undefined reference to
__main(), which makes sense since we are explicitly excluding the C runtime.I changed the test so that it works, does this work for you too? (edit: fixed formatting)
Last edit: Jason 2022-09-04
I did a bunch of debugging, and I came up with a much better solution. I just reordered some of the flag checks and now it works correctly for me. Diff attached.
With a little help, I've improved the patch further. Diff attached.
Hi!
I have found this bug because we cross compile NSIS, and users with mandatory ASLR could not use our installers (they got error code 0xc000007b).
I wanted to report back that adding
solves the problem for us! (We are using binutils 2.39).
Thanks!
Yeah, we added this a little while ago, it should be coming out with NSIS 3.09 at some point.
I don't understand this rsrc reloc thingies
Is what is is mentioned here
https://sourceforge.net/p/sevenzip/bugs/2373/
related to this?