https://sourceware.org/bugzilla/show_bug.cgi?id=34633
--- Comment #2 from Alex Henrie <alexhenrie24 at gmail dot com> --- Created attachment 17011 --> https://sourceware.org/bugzilla/attachment.cgi?id=17011&action=edit Source and binaries of test case compiled with Visual Studio 2026 (In reply to Alan Modra from comment #1) > Confirmed. gas puts an addend in the section contents for a relocation > against a symbol defined in the same file. ld then applies that addend when > linking. Someone would need to assemble the testcase using a microsoft > assembler to decide whether this is a bug in gas or a bug in ld. Thanks for confirming the bug. Despite the name, there isn't an exact analogue of __ms_hook_prologue__ in Microsoft land. __ms_hook_prologue__ in GCC is meant to imitate the /HOTPATCH and /FUNCTIONPADMIN compiler flags in MSVC. In 32-bit x86, /HOTPATCH adds a 2-byte no-op such as `mov %edi,%edi` to the beginning of every function. In other architectures, including x86-64, /HOTPATCH does nothing.[1] /HOTPATCH implies /FUNCTIONPADMIN,[2] which ensures that there are a few unused bytes before each function. The idea is that the empty space is replaced with a large jump to the function hook and the 2-byte no-op is replaced with a small jump to that previously empty space.[3] GCC has taken the concept a step further and makes __ms_hook_prologue__ insert an 8-byte no-op in x86-64. To try to answer your question about how the Microsoft assembler and linker work, I compiled my original C++ example for 32-bit x86 using Visual Studio 2026. I added a second function Foo::baz before Foo::bar to ensure that the compiler would have to insert padding between the two, and I've attached the entire project for you to take a look. The assembly code, object file, and executable all have a 2-byte no-op at the start of Foo::bar. In the object file, the main function looks like this: 00000000 <_main>: 0: 8b ff mov %edi,%edi 2: 55 push %ebp 3: 8b ec mov %esp,%ebp 5: e8 00 00 00 00 call a <_main+0xa> 6: DISP32 ?bar@Foo@@SAXXZ It looks to me like there is no extra addend. [1] https://learn.microsoft.com/en-us/cpp/build/reference/hotpatch-create-hotpatchable-image [2] https://learn.microsoft.com/en-us/cpp/build/reference/functionpadmin-create-hotpatchable-image [3] https://devblogs.microsoft.com/oldnewthing/20110921-00/?p=9583 -- You are receiving this mail because: You are on the CC list for the bug.
