[lld] r246901 - [elf2] Correctly handle sections with an alignment of 0. Spec says to treat it as an alignment of 1.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 7 16:09:49 PDT 2015


On Fri, Sep 4, 2015 at 10:01 PM, Michael Spencer <bigcheesegs at gmail.com> wrote:
> On Fri, Sep 4, 2015 at 5:48 PM, Davide Italiano <davide at freebsd.org> wrote:
>> On Fri, Sep 4, 2015 at 5:25 PM, Michael J. Spencer via llvm-commits
>> <llvm-commits at lists.llvm.org> wrote:
>>> Author: mspencer
>>> Date: Fri Sep  4 19:25:33 2015
>>> New Revision: 246901
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=246901&view=rev
>>> Log:
>>> [elf2] Correctly handle sections with an alignment of 0. Spec says to treat it as an alignment of 1.
>>>
>>> Added: lld/trunk/test/elf2/section-align-0.test
>>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/section-align-0.test?rev=246901&view=auto
>>> ==============================================================================
>>> --- lld/trunk/test/elf2/section-align-0.test (added)
>>> +++ lld/trunk/test/elf2/section-align-0.test Fri Sep  4 19:25:33 2015
>>> @@ -0,0 +1,19 @@
>>> +# RUN: yaml2obj -format elf %s -o %t
>>> +# RUN: lld -flavor gnu2 %t -o %tout
>>> +
>>
>> Is there any reason why you can't use assembler for testing?
>
> Feel free to change it if you know the magic incantation necessary to
> get llvm-mc to emit an alignment of 0.
>
> - Michael Spencer
>
>>

I spent some time analyzing this -- and I noticed your commit
indirectly exposes a couple of problems in llvm-mc:

1) .align directive refuses alignment 0 -- a comment in the code hints
this is done for GNU as compatibility, but it seems GNU as accepts
.align 0 (and silently rounds up alignment to 1). I have a patch to
fix that that I'll submit shortly .

$ ./llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu blah.s -o blah
blah.s:4:8: error: alignment must be a power of 2
.align 0
       ^
$ as blah.s -o blah
$

$ cat blah.s
.global _start
.global bar

.align 0
.text
_start:
bar:
  movl $bar, %edx

2) If we change align to 1 -- it seems llvm-mc doesn't honor it, but
silently rounds up that to 4. Not sure if this is a bug or intended
behavior. CC:ing Rafael as he did most of the recent work on ELF MC.

[llvm-mc]

$ readelf -S blah
  [ 2] .text             PROGBITS         0000000000000000  00000040
       0000000000000005  0000000000000000  AX       0     0     4

[GNU as]

$ readelf -S blah
  [ 1] .text             PROGBITS         0000000000000000  00000040
       0000000000000005  0000000000000000  AX       0     0     1

About your testcase -- I'm not sure if there's a way to emit a section
with alignment zero as also GNU as seems to round up that to 1
silently. I want to think a little bit harder about it, if somebody
has ideas on how to handle, they're welcome.

Thanks,

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list