The patch handls behavior of the disassembler when code and data are mixed in a text section.
When code an data are mixed in a section, the GNU disassembler acts in an interesting manner.
If told to disassemble text only (-d), it will interpret mixed data as data
$cat 1.c
int myInt = 1;
char myChar = 'b';
float myFloat = 1.2;
double myComm;
int main () {
return myInt;
}
$cat 1.t
SECTIONS {
.text : { *(.text)
*(.data.my* )
*(.bss*) }
}
$clang -c 1.c -fdata-sections
$ld 1.o -T 1.t
$objdump -d a.out
a.out: file format elf64-x86-64
Disassembly of section .text:
0000000000000040 <main>:
40: 55 push %rbp 41: 48 89 e5 mov %rsp,%rbp 44: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp) 4b: 8b 04 25 54 00 00 00 mov 0x54,%eax 52: 5d pop %rbp 53: c3 retq
0000000000000054 <myInt>:
54: 01 00 00 00 ....
0000000000000058 <myChar>:
58: 62 0f 1f 00 b...
000000000000005c <myFloat>:
5c: 9a 99 99 3f ...?
ARM variant has one more twist to it. When told to disassemble text only, it will interpret data if data is a standalone symbol, if it is part of a function, it marks it as a word/short etc.
$arm-none-eabi-gcc -c 1.c -fdata-sections
$arm-none-eabi-ld 1.o -t 1.t
$arm-none-eabi-objdump -d a.out
a.out: file format elf32-littlearm
Disassembly of section .text:
00008000 <main>:
8000: e52db004 push {fp} ; (str fp, [sp, #-4]!) 8004: e28db000 add fp, sp, #0 8008: e59f3010 ldr r3, [pc, #16] ; 8020 <main+0x20> 800c: e5933000 ldr r3, [r3] 8010: e1a00003 mov r0, r3 8014: e24bd000 sub sp, fp, #0 8018: e49db004 pop {fp} ; (ldr fp, [sp], #4) 801c: e12fff1e bx lr 8020: 00008024 .word 0x00008024 <=====marked as data
00008024 <myInt>:
8024: 00000001 .... <====interpreted as data
00008028 <myChar>:
8028: 00000062 b...
0000802c <myFloat>:
802c: 3f99999a ...?
If told to disassemble all - all objdump variants really disassemble the data as instructions:
$arm-none-eabi-objdump -D a.out
a.out: file format elf32-littlearm
Disassembly of section .text:
00008000 <main>:
8000: e52db004 push {fp} ; (str fp, [sp, #-4]!) 8004: e28db000 add fp, sp, #0 8008: e59f3010 ldr r3, [pc, #16] ; 8020 <main+0x20> 800c: e5933000 ldr r3, [r3] 8010: e1a00003 mov r0, r3 8014: e24bd000 sub sp, fp, #0 8018: e49db004 pop {fp} ; (ldr fp, [sp], #4) 801c: e12fff1e bx lr 8020: 00008024 andeq r8, r0, r4, lsr #32
00008024 <myInt>:
8024: 00000001 andeq r0, r0, r1
00008028 <myChar>:
8028: 00000062 andeq r0, r0, r2, rrx
0000802c <myFloat>:
802c: 3f99999a svccc 0x0099999a
Disassembly of section .bss:
00010030 <__bss_start>:
...