0

What happens if I dont provide any information in my likner script for some section? Where it would be located? For example if I have following linker script

SECTIONS {
    .text = { *(.text) }
}

And in my .S file I have some another section .section .mysection. What would heppen with mysection section in the resulting .o file? Would it even be loaded to the memory (protected mode)?

Also interesting what would heppen with .data and .bss sections.

UPD Consider .mysection doesn't contain any information. It just looks like this.

.section .mysection
stack_bottom:
.skip 16384
stack_top

But it's still interesting if it contains something.

PepeHands
  • 1,368
  • 5
  • 20
  • 36
  • I believe that any sections that were not processed in your SECTIONS directive are still placed into the target in the order the sections first appeared while processing the input object files. If you don't have a SECTIONS directive at all in your script, all the sections will appear in the order they are first encountered in the input file objects. – Michael Petch Dec 08 '15 at 22:23
  • @MichaelPetch but why when section `.mysection` is represented in `.o` file but it has no mark `loadable`. (I checked that with `objdump -s` and `objdump -h`). As I understand, it wont be loaded in the memory – PepeHands Dec 08 '15 at 22:30
  • Did `.mysection` have any data/code/definitions in it? If a section is encountered but has nothing declared in it, it will be discarded by default so wouldn't appear in the output. – Michael Petch Dec 08 '15 at 22:32
  • @MichaelPetch updated my question to answer your question – PepeHands Dec 08 '15 at 22:35
  • In the update you show that the section is `.bootstrap_stack` but you talk about `.mysection`? Are you sure you actually have a `.mysection` section? Or did you mean `.bootstrap_stack` instead of `.mysection`? If you don't list a section and it has something in it (.bootstrap_stack has 16384 of data in it), it should appear in the output object. Either you are looking for the wrong section in objdump or you aren't processing the object file (with _LD_) that has the section you are interested in. – Michael Petch Dec 08 '15 at 23:01
  • @MichaelPetch oh, sorry, yes, `mysection` is `bootstrap_stack`. Yes, it appears in `.o` file. But would it be loaded to the memory? It doesn't have `loadable` lable when I do `objdump -h` – PepeHands Dec 08 '15 at 23:06
  • @MichaelPetch it only has marks `CONTENTS, READONLY` – PepeHands Dec 08 '15 at 23:13
  • @MichaelPetch my is GNU assembler (as) but I think they have preatty the same dafaults. Thanks for help. Please, could you post your answer so I can accept it. – PepeHands Dec 08 '15 at 23:26
  • @MichaelPetch sorry, I deleted my last comment to you, it was incorrect. From GAS documentation: `If no flags are specified, the default flags depend upon the section name. If the section name is not recognized, the default will be for the section to have none of the above flags: it will not be allocated in memory, nor writable, nor executable. The section will contain data.` (see `elf` section here https://sourceware.org/binutils/docs/as/Section.html) – PepeHands Dec 08 '15 at 23:32
  • GAS has this in it's [documentation](https://sourceware.org/binutils/docs/as/Section.html) for ELF format: `If the section name is not recognized, the default will be for the section to have none of the above flags: it will not be allocated in memory, nor writable, nor executable. The section will contain data.` . So the CONTENTS READONLY appear correct for that too. – Michael Petch Dec 08 '15 at 23:32
  • @MichaelPetch yes, but it says `not be allocated in memory`. So I think this mean that `.mysection` won't be loaded to the memory when file executed – PepeHands Dec 08 '15 at 23:35
  • @MichaelPetch ok. it's 3 am in my country so I'll go to sleep now, but I will really appreciate if you will explain it. Sorry if I answer it and accept a little later) – PepeHands Dec 08 '15 at 23:41
  • I'm more use to NASM. In order for your section to be loaded into memory (and not just appear in the file) you should mark it as .`#alloc, #write`. Try `.section .mysection, #alloc, #write` . Since you are using it for the stack you want it writable. – Michael Petch Dec 08 '15 at 23:43

0 Answers0