Author Topic: Aligning in .bss section  (Read 16234 times)

Offline online

  • Jr. Member
  • *
  • Posts: 5
  • Country: cz
Aligning in .bss section
« on: January 04, 2013, 07:37:15 AM »
Hi all,

I have a problem with the correct alignment setting in the .bss section. My project is one .asm file, where I include some other .asm files. In this central file I have a .bss section defined, but without align=something because I don't need any alignment there. In one of these included .asm files I have [section .bss align=16], because I need the aligning for some buffers. But unfortunately it doesn't work, this is ignored. It works for me If I let it be like it is and add "align 16" on the line below the [section .bss align=16] definition. NASM surely complains and tells me that:
warning: attempt to initialize memory in a nobits section: ignored

but then it is aligned as I need ! :-)


My fault somewhere or is it a bug ?
Thx a lot for the answer :) !

online

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Aligning in .bss section
« Reply #1 on: January 04, 2013, 08:41:30 AM »
An "%include" is pretty much just a cut-and-paste. The included file is passed to the "assembler" routine as if it were a part of your original source, resulting in just one .bss section. If you need your .bss section aligned (more than default), I'd do it the first time "section .bss" is mentioned - main file or included files. If you need alignment on individual variables within the .bss section, the directive is "alignb", not "align". Says that in the manual, but a recent poster convinced me that it was a bug. Keith straightened us out!

Best,
Frank


Offline online

  • Jr. Member
  • *
  • Posts: 5
  • Country: cz
Re: Aligning in .bss section
« Reply #2 on: January 04, 2013, 09:45:21 AM »
Hello Frank,

thanks for the quick reply.
I tried to use the "alignb 16" in the .bss section of the included .asm source, but the situation was the same.
This is what I had there:

[section .bss]
          alignb 16
buffer  resb 8*16

It was not properly aligned, as seen in the map file:
16638  buffer   


I have to use [section .bss align=16] together with the alignb 16 again, then I get the desired
alignment and no warnings:

[section .bss align=16]
          alignb 16
buffer: resb 8*16

The buffer is correctly aligned then, the entry from the map file is:
16640  buffer

Where am I wrong ?

Btw. how does it work, if I have [section .bss] in the central .asm, and [section .bss align=16] in the included .asm file ? How will the resulting .bss section look like ?

Thanks again,
online

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Aligning in .bss section
« Reply #3 on: January 04, 2013, 02:05:14 PM »
I'm not sure I see the problem.

http://www.nasm.us/xdoc/2.10.07/html/nasmdoc4.html#section-4.12.12

Code: [Select]
[section .bss]
          alignb 16
buffer  resb 8*16

... should work, even without a "align=16" in the section declaration either in the main file or the included file. Seems to work for me. You got a fairly up-to-date version of Nasm? The "align" directive has not always worked properly, as I recall...

Best,
Frank


Offline online

  • Jr. Member
  • *
  • Posts: 5
  • Country: cz
Re: Aligning in .bss section
« Reply #4 on: January 04, 2013, 02:17:54 PM »
Ooops. That's it. I have the last version of NASM, but there's still the old version in the PATH...
Now it works prefectly as it should.

Thanks a lot,
online

Offline online

  • Jr. Member
  • *
  • Posts: 5
  • Country: cz
Re: Aligning in .bss section
« Reply #5 on: January 04, 2013, 02:58:58 PM »
Sorry for disturbing again, but  I have now one more problem after using the latest version, but completely another. This code:

[BITS 32]
CTRL.LRST      equ   0x00000008     ;link reset (1=reset)
CTRL.PHY_RST   equ   0x80000000     ;PHY Reset (0=normal,1=hw reset to PHY)
CTRL.VME      equ   0x40000000     ;VLAN Mode Enable
CTRL.ILOS      equ   0x00000080     ;invert loss of signal (0=do not invert)


[SECTION .text]

   mov   eax,~(CTRL.LRST|CTRL.PHY_RST|CTRL.VME|CTRL.ILOS)
   ret


generates this warning during compilation:
tmp.nsm:10: warning: dword data exceeds bounds

but the value is compiled correctly as 0x3fffff77 (one's complement of 0xc0000088). This warning was not there when I used the previous ancient version (2.05.01). Any idea why is this happening ?
« Last Edit: January 04, 2013, 03:08:07 PM by online »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Aligning in .bss section
« Reply #6 on: January 04, 2013, 03:51:48 PM »
I'm not really sure. I think Nasm is ASSuming that equates are 64-bit... just in case we need it. Without the "~", no warning, but with the "~" I think Nasm is ASSuming that those high bits (that we don't really want) are 1. I'm quite sure the warning can be safely ignored, but I really don't like telling anyone to do that! I can get Nasm to "shut up and assemble" by doing something like...

Code: [Select]
mov   eax,(~(CTRL.LRST|CTRL.PHY_RST|CTRL.VME|CTRL.ILOS)) & 0xffffffff

An ugly kludge that you really shouldn't need, but that's the best I can come up with at the moment. Sorry you're having so much trouble. We appreciate your feedback!

Best,
Frank

P.S. If you put the word "code" in "[]"s at the beginning of your code, and "/code" in "[]"s at the end, it sets off code nicely and makes it easy to "select" for cut-and-paste...

Offline online

  • Jr. Member
  • *
  • Posts: 5
  • Country: cz
Re: Aligning in .bss section
« Reply #7 on: January 04, 2013, 04:23:53 PM »
Haha, this can easily be true, that the EQUs are treated as 64bits, and after ~ operator it turns all these 63-32 bits to 1 causing the value to overflow. ;-)
I really appreciate your help, it's awesome. I am using NASM since its baby years and it's my no.1 assembler. So "thanks" to all people who develop it (or developed it in the past).

Thanks,
online