4

Source C code:

static int b;

Corresponding .bss section disassemble code in object file:

Disassembly of section .bss:

00000000 <b>:
   0:   00 00                   add    %al,(%eax)
   2:   00 00                   add    %al,(%eax)

Based on the info of section header:

  3 .bss          00000004  00000000  00000000  00000068  2**2
                  ALLOC

Obviously, .bss exists and occupies a certain space (matches with hex dump)!

Two things I wanna ask,

1.When I use readelf to dump .bss section:

readelf -x .bss section_test.o
Section '.bss' has no data to dump.

I just don't get it. It definitely has some data, right?

2.How to understand those code in .bss section? I mean, I totally understand them individually as assembly, but I just feel kinda confused about why they are here?

Thx.

Extra info: MacOS using Docker (Ubuntu), AT&T syntax, x86_64 Arch(physical) but using elf_i386(32-bit) arch when compiling and linking stage.

Edee
  • 1,746
  • 2
  • 6
  • 14
  • 3
    The `bss` section has a size but no data. It's the section for data initialised by zeroes which can be omitted from the binary image. `objdump` probably just shows you the zeroes that will be generated in RAM when the binary is loaded. – fuz Nov 23 '19 at 14:40
  • 1
    Yeah, I think I do understand what you said. But I just wanna figure out what are those disassemble code doing ? And doing for what? I know it sounds kinda ridiculous, but is that because all 00 00 section are translated into add %al,(%eax) as disassembly when we dump the object file? – Edee Nov 23 '19 at 14:42
  • 5
    It's just that `00 00` is the opcode for `add %al, (%eax)`. The content of `.bss` is not meant to be executed. It's just the memory for the variable `b`. – fuz Nov 23 '19 at 14:50
  • 4
    when you use objdump to disassemble the file it assumes that all bytes are instructions and disassembles them when most of the sections are not code, so the disassembly is to be ignored it is not machine code. its data. – old_timer Nov 23 '19 at 15:29

0 Answers0