Force power of 2 function alignment s.t alignment % some other value == alignment

Viewed 48

Basically I am looking for a way to force a specific relative alignment

i.e I want to gurantee that for some other value m s.t m > n alignment_of(foo) % 2^m == 2^n i.e:

.align 2^m;
.global foo;
.type foo, @function
foo:
// 2^n nops
// actual function start

but hopefully without having entry have to go through a bunch of a nops.

I need it to work with foo being linked with C code.

1 Answers

You can always add padding before the start of the function. The perhaps easiest way is to do something like this:

        .p2align m
        .byte 0xcc
        .p2align n, 0xcc
foo:    ...

Here, I've explicitly padded the code with 0xcc bytes. You can use whatever padding you like or leave out the 0xcc to get nop instructions of various lengths

Related