android / android/ndk

[Bug]: stack alignment armeabi-v7a

Open
#1,743 0 comments 1 reaction 1 assignee Claimed by @pirama-arumuga-nainar View on GitHub
bug
Dominant language
No language data
Stars
2.3k
Forks
310
PR merge metrics
No merged PRs in 30d

Description

### Description

I tried to align sp in a shared object with following flags:
```
-mstack-alignment=n // sets the alignment to n bytes
-mstackrealign // forces the previous set alignment
```
after compilation with `n=16` the following bfc instruction appeared at the top of every function.

`0x000007c8 1fd0c1e7 bfc sp, 0, 2`

In my opinion this is not correct since this refers to 4 byte sp alignment.

However if I set alignas(16) char buf[4] at the beginning of a function, the alignment looks correct.

`0x000007c8 1fd0c3e7 bfc sp, 0, 4`

Appears on `armv7a-linux-androideabiX-clang++` compilers
NDK's tested 23 & 25
On arm64 everything works

**Example:**

**test.cpp**

```
int my_func()
{
return 1;
}
```
**Cmdline:**

`armv7a-linux-androideabi23-clang++ test.cpp -shared -mstack-alignment=16 -mstackrealign`

### Upstream bug

_No response_

### Commit to cherry-pick

_No response_

### Affected versions

r23, r25

### Canary version

_No response_

### Host OS

Linux

### Host OS version

20.04.3 LTS

### Affected ABIs

armeabi-v7a

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.