Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New gcc breaks compilation of -Os programs that use problematic static functions #247

Closed
CelesteBlue-dev opened this issue Sep 23, 2023 · 1 comment

Comments

@CelesteBlue-dev
Copy link

CelesteBlue-dev commented Sep 23, 2023

Newer gcc (>8 maybe) uses different optimizations, which breaks compilation of some programs that have the -Os flag and use problematic static functions like memset.

Logs:

arm-vita-eabi-gcc -fPIE -fno-zero-initialized-in-bss -std=c99 -mcpu=cortex-a9 -Os -mthumb   -c -o payload.o payload.c
arm-vita-eabi-gcc -fPIE -fno-zero-initialized-in-bss -std=c99 -mcpu=cortex-a9 -Os -mthumb payload.o -o payload.elf -T linker.x -nostartfiles -nostdlib -pie
/usr/local/vitasdk/bin/../lib/gcc/arm-vita-eabi/10.3.0/../../../../arm-vita-eabi/bin/ld.exe: payload.o: in function `one':
payload.c:(.text+0xa34): undefined reference to `memset'
/usr/local/vitasdk/bin/../lib/gcc/arm-vita-eabi/10.3.0/../../../../arm-vita-eabi/bin/ld.exe: payload.o: in function `two':
payload.c:(.text+0x19b0): undefined reference to `memset'
/usr/local/vitasdk/bin/../lib/gcc/arm-vita-eabi/10.3.0/../../../../arm-vita-eabi/bin/ld.exe: payload.o: in function `three':
payload.c:(.text+0x1faa): undefined reference to `memset'
collect2.exe: error: ld returned 1 exit status

Known workarounds are:

  1. Replace -Os with -O0. Compiles but produces a broken executable (kernel panic).
  2. Search what optimizations are enabled on gcc10 for -Os that are not on gcc8, and disable them. Not tried.
  3. Remove the static attribute of the problematic function. Produces a good executable but modifies output size because of more or less optimizations.
  4. Add -fno-builtin flag but attribute(used) might be needed for those problematic static functions

This issue might have a common cause with issue #226.

A valid fix should be either a regression in gcc10 directly, or an automating of broken optimizations disabling.

@CelesteBlue-dev CelesteBlue-dev changed the title New gcc breaks compilation of -Os programs that redefine memset or memcpy New gcc breaks compilation of -Os programs that use problematic static functions Sep 23, 2023
@Princess-of-Sleeping
Copy link
Contributor

This may not be a gcc break, A simple gcc loop optimization as it can be fixed by adding -fno-builtin as shown in workarounds 4.

gcc wants to use memset for code like

for(int i=0;i<0x2000;i++){
  array[i] = x;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant