[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug gas/29145] New: GAS always generates padding instructions regardles
From: |
lh_mouse at 126 dot com |
Subject: |
[Bug gas/29145] New: GAS always generates padding instructions regardless of `--no-pad-sections` |
Date: |
Fri, 13 May 2022 07:05:18 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=29145
Bug ID: 29145
Summary: GAS always generates padding instructions regardless
of `--no-pad-sections`
Product: binutils
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: gas
Assignee: unassigned at sourceware dot org
Reporter: lh_mouse at 126 dot com
Target Milestone: ---
Given this simple C program:
```
int foo(int a);
int bar(int a) { return foo(a); }
```
We compile it with GCC, targeting linux:
```
lh_mouse@lhmouse-dev ~ $ x86_64-linux-gnu-gcc -Os test.c -S -o test.s && cat
test.s
.file "test.c"
.text
.globl bar
.type bar, @function
bar:
.LFB0:
.cfi_startproc
jmp foo@PLT
.cfi_endproc
.LFE0:
.size bar, .-bar
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
```
The function contains only a `jmp` instruction. We assemble this file:
```
lh_mouse@lhmouse-dev ~ $ x86_64-linux-gnu-as test.s -o test.o && objdump -h
test.o
test.o: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000005 0000000000000000 0000000000000000 00000040 2**0
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 0000000000000000 0000000000000000 00000045 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 0000000000000000 0000000000000000 00000045 2**0
ALLOC
3 .comment 0000001d 0000000000000000 0000000000000000 00000045 2**0
CONTENTS, READONLY
4 .note.GNU-stack 00000000 0000000000000000 0000000000000000 00000062
2**0
CONTENTS, READONLY
5 .eh_frame 00000030 0000000000000000 0000000000000000 00000068 2**3
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
```
The `.text` section has a size of 5 and alignment of 1, which looks good, and
does what `-Os` is presumed to do.
We attempt to compile the same code targeting mingw-w64:
```
lh_mouse@lhmouse-dev ~ $ x86_64-w64-mingw32-gcc -Os test.c -S -o test.s && cat
test.s
.file "test.c"
.text
.globl bar
.def bar; .scl 2; .type 32; .endef
.seh_proc bar
bar:
.seh_endprologue
jmp foo
.seh_endproc
.ident "GCC: (GNU) 8.3-win32 20190406"
.def foo; .scl 2; .type 32; .endef
```
The function still contains only a `jmp` instruction. But when we assemble it:
```
lh_mouse@lhmouse-dev ~ $ x86_64-w64-mingw32-as test.s -o test.o && objdump -h
test.o
test.o: file format pe-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000010 0000000000000000 0000000000000000 00000104 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 0000000000000000 0000000000000000 00000000 2**4
ALLOC, LOAD, DATA
2 .bss 00000000 0000000000000000 0000000000000000 00000000 2**4
ALLOC
3 .xdata 00000004 0000000000000000 0000000000000000 00000114 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .pdata 0000000c 0000000000000000 0000000000000000 00000118 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
5 .rdata$zzz 00000020 0000000000000000 0000000000000000 00000124 2**4
CONTENTS, ALLOC, LOAD, READONLY, DATA
```
This time the `.text` section has a size of 16 and alignment of 16 bytes, which
is undesired.
This also results in extra NOPs in the object file:
```
lh_mouse@lhmouse-dev ~ $ objdump -d test.o
test.o: file format pe-x86-64
Disassembly of section .text:
0000000000000000 <bar>:
0: e9 00 00 00 00 jmpq 5 <bar+0x5>
5: 90 nop
6: 90 nop
7: 90 nop
8: 90 nop
9: 90 nop
a: 90 nop
b: 90 nop
c: 90 nop
d: 90 nop
e: 90 nop
f: 90 nop
```
which LD will not be able to remove.
Adding `.p2align` directives in 'test.s' seems only able to increase the
alignment (requests for 32, 64, etc. work), but it is not possible to decrease
the alignment (requests for 1, 2, 4, 8 are ignroed). Could this be improved a
little?
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug gas/29145] New: GAS always generates padding instructions regardless of `--no-pad-sections`,
lh_mouse at 126 dot com <=
- [Bug gas/29145] GAS always generates padding instructions regardless of `--no-pad-sections`, lh_mouse at 126 dot com, 2022/05/13
- [Bug gas/29145] GAS always generates padding instructions regardless of `--no-pad-sections`, nickc at redhat dot com, 2022/05/18
- [Bug gas/29145] GAS always generates padding instructions regardless of `--no-pad-sections`, lh_mouse at 126 dot com, 2022/05/18
- [Bug gas/29145] GAS always generates padding instructions regardless of `--no-pad-sections`, nickc at redhat dot com, 2022/05/23
- [Bug gas/29145] GAS always generates padding instructions regardless of `--no-pad-sections`, lh_mouse at 126 dot com, 2022/05/23
- [Bug gas/29145] GAS always generates padding instructions regardless of `--no-pad-sections`, lh_mouse at 126 dot com, 2022/05/23