https://sourceware.org/bugzilla/show_bug.cgi?id=30359
--- Comment #4 from Pali Rohár <pali at kernel dot org> --- (In reply to Nick Clifton from comment #3) > (In reply to Pali Rohár from comment #2) > > If adding empty import table and something in code .text sections is feature > > of the linker, it is somewhere documented? > > No. :-( > > > What it is doing and what is > > putting there (as those sections are not in any user supplied input file)? > > The (builtin, default) linker script is the cause. Ok! > > And I'm interesting why it is doing, it is some requirement for some SW? > > Just I'm currious here. > > The PE linker script automatically puts some constant values into the .text > section as markers between the normal code and the constructors and > destructors. If you run "ld --verbose" you will see this in the details for > the .text section: > > ... > LONG (-1); LONG (-1); > KEEP (*(.ctors)); > KEEP (*(.ctor)); > KEEP (*(SORT_BY_NAME(.ctors.*))); > LONG (0); LONG (0); > /* See comment about __CTOR_LIST__ above. The same reasoning > applies here too. */ > ___DTOR_LIST__ = .; > __DTOR_LIST__ = .; > LONG (-1); LONG (-1); > KEEP (*(.dtors)); > KEEP (*(.dtor)); > KEEP (*(SORT_BY_NAME(.dtors.*))); > LONG (0); LONG (0); > ... > > These markers are used by the execution startup code to help find the two > tables. I see... But in this case there is nothing in .text section, just those markers. Does not linker script language support conditions to put markers only when at least one of those input sections is non-empty? So when input for that section is completely empty then also output section would be empty. > > > And about objcopy --remove-section workaround, this is problematic because > > for automatization, it is needed to know what sections has to be removed - > > meaning ability to ask LD what additional section it added there. > > In which case, just use --only-section instead. ie: > > $ objcopy --only-section=.rsrc test-rsrc.dll test-rsrc.3.dll > $ objdump -h test-rsrc.3.dll > test-rsrc.3.dll: file format pei-i386 > > Sections: > Idx Name Size VMA LMA File off Algn > 0 .rsrc 000000b8 10003000 10003000 00000200 2**2 > CONTENTS, ALLOC, LOAD, READONLY, DATA This looks better. objcopy needs to be called also with -S to drop symbols which that LD script added. But still this --only-section does not remove .idata completelly. There is still reference to (now removed) import table and objdump prints warning about it. Visible also in readpe. $ readpe test-rsrc.3.dll | grep -A 6 'Data directories' export directory not found Data directories Directory IMAGE_DIRECTORY_ENTRY_IMPORT: 0x2000 (20 bytes) Directory IMAGE_DIRECTORY_ENTRY_RESOURCE: 0x3000 (184 bytes) Imported functions Sections $ i686-w64-mingw32-objdump -p test-rsrc.3.dll | grep -A 19 'The Data Directory' The Data Directory Entry 0 00000000 00000000 Export Directory [.edata (or where ever we found it)] Entry 1 00002000 00000014 Import Directory [parts of .idata] Entry 2 00003000 000000b8 Resource Directory [.rsrc] Entry 3 00000000 00000000 Exception Directory [.pdata] Entry 4 00000000 00000000 Security Directory Entry 5 00000000 00000000 Base Relocation Directory [.reloc] Entry 6 00000000 00000000 Debug Directory Entry 7 00000000 00000000 Description Directory Entry 8 00000000 00000000 Special Directory Entry 9 00000000 00000000 Thread Storage Directory [.tls] Entry a 00000000 00000000 Load Configuration Directory Entry b 00000000 00000000 Bound Import Directory Entry c 00000000 00000000 Import Address Table Directory Entry d 00000000 00000000 Delay Import Directory Entry e 00000000 00000000 CLR Runtime Header Entry f 00000000 00000000 Reserved There is an import table, but the section containing it could not be found -- You are receiving this mail because: You are on the CC list for the bug.