[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug binutils/30496] New: Add support for PE IMAGE_SCN_MEM_16BIT section
From: |
pali at kernel dot org |
Subject: |
[Bug binutils/30496] New: Add support for PE IMAGE_SCN_MEM_16BIT section characteristic |
Date: |
Sun, 28 May 2023 13:42:53 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=30496
Bug ID: 30496
Summary: Add support for PE IMAGE_SCN_MEM_16BIT section
characteristic
Product: binutils
Version: 2.39
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: binutils
Assignee: unassigned at sourceware dot org
Reporter: pali at kernel dot org
Target Milestone: ---
PE for machine type of IMAGE_FILE_MACHINE_I386 (0x014c) can contain
IMAGE_SCN_MEM_16BIT (0x00020000) in section characteristics. When
IMAGE_SCN_MEM_16BIT is specified then section contain 16-bit x86 code.
Microsoft DUMPBIN.EXE recognize this characteristic and show its name as
"Purgeable or 16-Bit". And sections marked with this characteristic disassemble
as 16-bit instead of default 32-bit.
Note that PE IMAGE_SCN_MEM_PURGEABLE characteristic has same value as
IMAGE_SCN_MEM_16BIT = 0x00020000, but my experiments reveal that for MS tools
IMAGE_SCN_MEM_16BIT seems to be I386 specific and IMAGE_SCN_MEM_PURGEABLE seems
to be M68K specific.
Here is very simple object file test.obj with two functions _test32 and _test16
which are in different sections with and without IMAGE_SCN_MEM_16BIT
characteristics.
$ xxd test.obj
00000000: 4c01 0200 a94f 7364 6a00 0000 0a00 0000 L....Osdj.......
00000010: 0000 0000 2e74 6578 7400 0000 0000 0000 .....text.......
00000020: 0000 0000 0300 0000 6400 0000 0000 0000 ........d.......
00000030: 0000 0000 0000 0000 2010 1060 2e74 6578 ........ ..`.tex
00000040: 7400 0000 0300 0000 0000 0000 0300 0000 t...............
00000050: 6700 0000 0000 0000 0000 0000 0000 0000 g...............
00000060: 2010 1260 33c0 c333 c0c3 2e66 696c 6500 ..`3..3...file.
00000070: 0000 0000 0000 feff 0000 6701 7465 7374 ..........g.test
00000080: 2e63 0000 0000 0000 0000 0000 0000 5f74 .c............_t
00000090: 6573 7433 3200 0000 0000 0000 2000 0200 est32....... ...
000000a0: 2e74 6578 7400 0000 0000 0000 0100 0000 .text...........
000000b0: 0301 0300 0000 0000 0000 0000 0000 0000 ................
000000c0: 0100 0000 5f74 6573 7433 3200 0000 0000 ...._test32.....
000000d0: 0100 2000 0200 5f74 6573 7431 3600 0000 .. ..._test16...
000000e0: 0000 0000 2000 0200 2e74 6578 7400 0000 .... ....text...
000000f0: 0000 0000 0200 0000 0301 0300 0000 0000 ................
00000100: 0000 0000 0000 0000 0100 0000 5f74 6573 ............_tes
00000110: 7431 3600 0000 0000 0200 2000 0200 0400 t16....... .....
00000120: 0000 ..
Microsoft DUMPBIN.EXE correcly recognize IMAGE_SCN_MEM_16BIT in _test16 and
disassemble "0x33 0xC0" as "xor ax,ax":
$ DUMPBIN.EXE /DISASM /HEADERS test.obj
...
SECTION HEADER #1
.text name
0 physical address
0 virtual address
3 size of raw data
64 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
60101020 flags
Code
Communal; sym= _test32
1 byte align
Execute Read
_test32:
00000000: 33 C0 xor eax,eax
00000002: C3 ret
DUMPBIN : warning LNK4078: multiple ".text" sections found with different
attributes (60121020)
SECTION HEADER #2
.text name
3 physical address
0 virtual address
3 size of raw data
67 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
60121020 flags
Code
Communal; sym= _test16
Purgeable or 16-Bit
1 byte align
Execute Read
_test16:
0002:0000: 33 C0 xor ax,ax
0002:0002: C3 ret
Summary
3 .text
3 .text
But GNU objdump does not recognize it and disassemble "0x33 0xC0" in 32-bit
mode as "xor %eax,%eax":
$ i686-w64-mingw32-objdump -d test.mod.obj
test.obj: file format pe-i386
Disassembly of section .text:
00000000 <_test32>:
0: 33 c0 xor %eax,%eax
2: c3 ret
Disassembly of section .text:
00000000 <_test16>:
0: 33 c0 xor %eax,%eax
2: c3 ret
Also assembling simple code with .code16 directive with GNU AS does not set
IMAGE_SCN_MEM_16BIT section characteristic.
Test case:
$ cat test-16bit.S
.section .text32, "rx0"
_test32:
xor %eax, %eax
ret
.section .text16, "rx0"
.code16
_test16:
xor %ax, %ax
ret
$ i686-w64-mingw32-as -o test-16bit.o test-16bit.S
$ i686-w64-mingw32-objdump -d test-16bit.o
test-16bit.o: file format pe-i386
Disassembly of section .text32:
00000000 <_test32>:
0: 31 c0 xor %eax,%eax
2: c3 ret
Disassembly of section .text16:
00000000 <_test16>:
0: 31 c0 xor %eax,%eax
2: c3 ret
$ DUMPBIN.EXE /DISASM /HEADERS test-16bit.o
...
SECTION HEADER #5
.text16 name
0 physical address
0 virtual address
3 size of raw data
DF file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
60100060 flags
Code
Initialized Data
1 byte align
Execute Read
_test16:
00000000: 31 C0 xor eax,eax
00000002: C3 ret
It would be really nice if GNU objdump recognize IMAGE_SCN_MEM_16BIT for
IMAGE_FILE_MACHINE_I386 and disassemble code in 16-bit. I know that objdump can
be instructed to disassemble 16-bit code by argument -Maddr16,data16 but
autodetection is better as it can detect "mixed" object files (with contain
both 32-bit and 16-bit x86 code).
Also it would be nice if GNU AS .code16 directive can set IMAGE_SCN_MEM_16BIT.
--
You are receiving this mail because:
You are on the CC list for the bug.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug binutils/30496] New: Add support for PE IMAGE_SCN_MEM_16BIT section characteristic,
pali at kernel dot org <=