Bug 16321 - Gold generates unnecessary padding for .bss section offset
Summary: Gold generates unnecessary padding for .bss section offset
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-11 21:22 UTC by H.J. Lu
Modified: 2016-12-12 01:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2013-12-11 21:22:54 UTC
[hjl@gnu-6 relro-6]$ cat x.c
static char bss[40];
char const *p1 =  &bss[0];
char const p2[1] = { 1 };
[hjl@gnu-6 relro-6]$ make
gcc -fuse-ld=gold -B./  -O2 -fPIC   -c -o x.o x.c
./ld.gold -shared -z relro -o libx.so x.o
./strip --strip-debug libx.so -o bar
readelf -lSW bar > new.txt
readelf -lSW libx.so > old.txt
diff -up old.txt new.txt
--- old.txt	2013-12-11 13:19:00.174333763 -0800
+++ new.txt	2013-12-11 13:19:00.170333768 -0800
@@ -1,4 +1,4 @@
-There are 15 section headers, starting at offset 0x11e0:
+There are 15 section headers, starting at offset 0x10d8:
 
 Section Headers:
   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
@@ -11,12 +11,12 @@ Section Headers:
   [ 6] .rodata           PROGBITS        0000000000000288 000288 000001 00   A  0   0  1
   [ 7] .dynamic          DYNAMIC         0000000000001f10 000f10 0000f0 10  WA  2   0  8
   [ 8] .data             PROGBITS        0000000000002000 001000 000008 00  WA  0   0  8
-  [ 9] .bss              NOBITS          0000000000002020 001020 000028 00  WA  0   0 32
+  [ 9] .bss              NOBITS          0000000000002020 001008 000028 00  WA  0   0 32
   [10] .comment          PROGBITS        0000000000000000 001008 00002d 01  MS  0   0  1
   [11] .note.gnu.gold-version NOTE            0000000000000000 001038 00001c 00      0   0  4
-  [12] .symtab           SYMTAB          0000000000000000 001058 0000d8 18     13   4  8
-  [13] .strtab           STRTAB          0000000000000000 001130 000030 00      0   0  1
-  [14] .shstrtab         STRTAB          0000000000000000 001160 00007d 00      0   0  1
+  [12] .shstrtab         STRTAB          0000000000000000 001054 00007d 00      0   0  1
+  [13] .symtab           SYMTAB          0000000000000000 001498 0001c8 18     14  14  8
+  [14] .strtab           STRTAB          0000000000000000 001660 00002c 00      0   0  1
 Key to Flags:
   W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
   I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
make: *** [all] Error 1
[hjl@gnu-6 relro-6]$ 

Gold generates

[ 9] .bss              NOBITS          0000000000002020 001020 000028 00  WA  0   0 32

Why does gold set offset to 0x1020 instead of 0x1008, which is right
after .data.  0x1020 is the middle of .comment section.
Comment 1 Cary Coutant 2016-12-12 01:41:53 UTC
While this wasn't really a bug IMO (the file offset means nothing for a NOBITS section), the patch for PR 16711 may in fact result in the output you expect here.