https://bugs.winehq.org/show_bug.cgi?id=28140
Anastasius Focht focht@gmx.net changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |NEW Component|comctl32 |kernel32
--- Comment #16 from Anastasius Focht focht@gmx.net --- Hello Paul,
--- quote --- Must be compiler version and / or optimization flags. Looks like in my case compiler correctly deduced it doesn't need PIC prolog in this function. --- quote ---
the only case for '-fPIC' where a load of GOT register is emitted into prolog code is indeed "no optimization". Gcc seems to intentionally generate "bad" code here, including a redundant load of GOT register.
https://source.winehq.org/git/wine.git/blob/HEAD:/dlls/kernel32/resource.c#l...
--- snip --- 617 /********************************************************************** 618 * SizeofResource (KERNEL32.@) 619 */ 620 DWORD WINAPI SizeofResource( HINSTANCE hModule, HRSRC hRsrc ) 621 { 622 if (!hRsrc) return 0; 623 return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size; 624 } --- snip ---
Quick check:
--- snip --- $ echo "" | gcc -E -m32 -v - 2>&1 | grep -i cc COLLECT_GCC=/usr/bin/gcc Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux gcc version 8.3.1 20190223 (Red Hat 8.3.1-2) (GCC) COLLECT_GCC_OPTIONS='-E' '-m32' '-v' '-mtune=generic' '-march=i686' /usr/libexec/gcc/x86_64-redhat-linux/8/cc1 -E -quiet -v -imultilib 32 - -m32 -mtune=generic -march=i686 ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/8/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include" /usr/lib/gcc/x86_64-redhat-linux/8/include COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/8/:/usr/libexec/gcc/x86_64-redhat-linux/8/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/8/:/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/8/32/:/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-redhat-linux/8/:/usr/lib/gcc/x86_64-redhat-linux/8/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-E' '-m32' '-v' '-mtune=generic' '-march=i686' --- snip ---
--- snip --- $ pwd /home/focht/projects/wine/mainline-build-i686/dlls/kernel32
$ rm resource.o
$ gcc -m32 -c -o resource.o /home/focht/projects/wine/mainline-src/dlls/kernel32/resource.c -I. \ -I/home/focht/projects/wine/mainline-src/dlls/kernel32 -I../../include \ -I/home/focht/projects/wine/mainline-src/include -D__WINESRC__ -D_KERNEL32_ -D_NORMALIZE_ \ -D_REENTRANT -fPIC -Wall -pipe -fno-strict-aliasing -Wdeclaration-after-statement -Wempty-body \ -Wignored-qualifiers -Wno-packed-not-aligned -Wshift-overflow=2 -Wstrict-prototypes -Wtype-limits \ -Wunused-but-set-parameter -Wvla -Wwrite-strings -Wpointer-arith -Wlogical-op \ -gdwarf-2 -gstrict-dwarf -fno-omit-frame-pointer -g
$ /home/focht/projects/wine/mainline-build-x86_64/tools/winegcc/winegcc -o kernel32.dll.so \ -B/home/focht/projects/wine/mainline-build-x86_64/tools/winebuild --sysroot=../.. -m32 \ -fasynchronous-unwind-tables -shared /home/focht/projects/wine/mainline-src/dlls/kernel32/kernel32.spec \ -nodefaultlibs -Wb,-F,KERNEL32.dll -Wl,--image-base,0x7b400000 actctx.o atom.o change.o comm.o \ computername.o console.o cpu.o debugger.o editline.o environ.o except.o fiber.o file.o \ format_msg.o heap.o kernel_main.o lcformat.o locale.o lzexpand.o module.o nameprep.o oldconfig.o \ path.o powermgnt.o process.o profile.o resource.o string.o sync.o tape.o term.o thread.o time.o \ toolhelp.o version.o virtual.o volume.o wer.o locale_rc.res version.res winerror.res \ ../../dlls/winecrt0/libwinecrt0.a -lntdll ../../libs/port/libwine_port.a --- snip ---
With '-O0':
--- snip --- $ gdb kernel32.dll.so -batch -ex 'disassemble SizeofResource' Dump of assembler code for function SizeofResource: 0x7b47a0b5 <+0>: push %ebp 0x7b47a0b6 <+1>: mov %esp,%ebp 0x7b47a0b8 <+3>: call 0x7b42f028 <__x86.get_pc_thunk.ax> 0x7b47a0bd <+8>: add $0x1e6f43,%eax 0x7b47a0c2 <+13>: cmpl $0x0,0xc(%ebp) 0x7b47a0c6 <+17>: jne 0x7b47a0cf <SizeofResource+26> 0x7b47a0c8 <+19>: mov $0x0,%eax 0x7b47a0cd <+24>: jmp 0x7b47a0d5 <SizeofResource+32> 0x7b47a0cf <+26>: mov 0xc(%ebp),%eax 0x7b47a0d2 <+29>: mov 0x4(%eax),%eax 0x7b47a0d5 <+32>: pop %ebp 0x7b47a0d6 <+33>: ret $0x8 End of assembler dump. --- snip ---
With '-O1':
--- snip --- $ gdb kernel32.dll.so -batch -ex 'disassemble SizeofResource' Dump of assembler code for function SizeofResource: 0x7b47b9e2 <+0>: push %ebp 0x7b47b9e3 <+1>: mov %esp,%ebp 0x7b47b9e5 <+3>: mov 0xc(%ebp),%eax 0x7b47b9e8 <+6>: test %eax,%eax 0x7b47b9ea <+8>: je 0x7b47b9f3 <SizeofResource+17> 0x7b47b9ec <+10>: mov 0x4(%eax),%eax 0x7b47b9ef <+13>: pop %ebp 0x7b47b9f0 <+14>: ret $0x8 0x7b47b9f3 <+17>: mov $0x0,%eax 0x7b47b9f8 <+22>: jmp 0x7b47b9ef <SizeofResource+13> End of assembler dump. --- snip ---
With '-O2':
--- snip --- $ gdb kernel32.dll.so -batch -ex 'disassemble SizeofResource' Dump of assembler code for function SizeofResource: 0x7b47c010 <+0>: push %ebp 0x7b47c011 <+1>: mov %esp,%ebp 0x7b47c013 <+3>: mov 0xc(%ebp),%eax 0x7b47c016 <+6>: test %eax,%eax 0x7b47c018 <+8>: je 0x7b47c028 <SizeofResource+24> 0x7b47c01a <+10>: mov 0x4(%eax),%eax 0x7b47c01d <+13>: pop %ebp 0x7b47c01e <+14>: ret $0x8 0x7b47c021 <+17>: lea 0x0(%esi,%eiz,1),%esi 0x7b47c028 <+24>: xor %eax,%eax 0x7b47c02a <+26>: pop %ebp 0x7b47c02b <+27>: ret $0x8 End of assembler dump.
--- snip ---
With '-O3'
--- snip --- $ gdb kernel32.dll.so -batch -ex 'disassemble SizeofResource' Dump of assembler code for function SizeofResource: 0x7b47cd30 <+0>: push %ebp 0x7b47cd31 <+1>: mov %esp,%ebp 0x7b47cd33 <+3>: mov 0xc(%ebp),%eax 0x7b47cd36 <+6>: test %eax,%eax 0x7b47cd38 <+8>: je 0x7b47cd48 <SizeofResource+24> 0x7b47cd3a <+10>: mov 0x4(%eax),%eax 0x7b47cd3d <+13>: pop %ebp 0x7b47cd3e <+14>: ret $0x8 0x7b47cd41 <+17>: lea 0x0(%esi,%eiz,1),%esi 0x7b47cd48 <+24>: xor %eax,%eax 0x7b47cd4a <+26>: pop %ebp 0x7b47cd4b <+27>: ret $0x8 End of assembler dump. --- snip ---
With '-Os'
--- snip --- $ gdb kernel32.dll.so -batch -ex 'disassemble SizeofResource' Dump of assembler code for function SizeofResource: 0x7b47b4c3 <+0>: push %ebp 0x7b47b4c4 <+1>: xor %eax,%eax 0x7b47b4c6 <+3>: mov %esp,%ebp 0x7b47b4c8 <+5>: mov 0xc(%ebp),%edx 0x7b47b4cb <+8>: test %edx,%edx 0x7b47b4cd <+10>: je 0x7b47b4d2 <SizeofResource+15> 0x7b47b4cf <+12>: mov 0x4(%edx),%eax 0x7b47b4d2 <+15>: pop %ebp 0x7b47b4d3 <+16>: ret $0x8 End of assembler dump. --- snip ---
Regards