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

Using LTO on PowerPC generates broken binaries #46697

Closed
pkubaj opened this issue Aug 29, 2020 · 10 comments
Closed

Using LTO on PowerPC generates broken binaries #46697

pkubaj opened this issue Aug 29, 2020 · 10 comments
Labels
bugzilla Issues migrated from bugzilla lld:ELF

Comments

@pkubaj
Copy link
Contributor

pkubaj commented Aug 29, 2020

Bugzilla Link 47353
Version unspecified
OS FreeBSD
CC @adalava,@nemanjai,@smithp35

Extended Description

FreeBSD head, LLVM 11.0.0-rc2, powerpc64 elfv2

FreeBSD uses GH BC as its bc implementation. It tries to build using -flto, but it's disabled for powerpc64, because it generates a broken bc that segfaults at start.

I also tried to build ffmpeg 4.3.1 with --enable-lto passed to configure. -flto is passed properly and ffmpeg builds fine. I can also compile software that links to ffmpeg libraries. However, running such software (e.g. mpv, or just ffmpeg itself) leads to instant segfault.

Compiling such software with GCC mitigates this issue.

@nemanjai
Copy link
Member

nemanjai commented Sep 8, 2020

I understand that a reproducer is hard to provide for something like this. However, are you able to at least provide instructions on how to build/configure this? Is it possible to do this on a big endian Linux system (i.e. after downloading some custom ELFv2 libraries)? If not, are you aware of any publicly accessible system that we can get into to reproduce this?

Perhaps at least start with information about the HW, stack trace, disassembly in the debugger of the place where the segfault happens...

@pkubaj
Copy link
Contributor Author

pkubaj commented Jan 28, 2021

Full reproducer, it looks like even hello world fails:
pkubaj@talos:$$ cc -v
FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe)
Target: powerpc64-unknown-freebsd13.0
Thread model: posix
InstalledDir: /usr/bin
pkubaj@talos:$
$ cat test.c
#include <stdio.h>

int main(void)
{
printf("Hello world!\n");
}
pkubaj@talos:$$ cc test.c
pkubaj@talos:$
$ ./a.out
Hello world!
pkubaj@talos:$$ cc -flto test.c
pkubaj@talos:$
$ ./a.out
Segmentation fault (core dumped)

@pkubaj
Copy link
Contributor Author

pkubaj commented Jan 28, 2021

This seems to be an issue only on 64-bits on BE (FreeBSD uses ELFv2). LE works fine and 32-bit BE is also fine.

@pkubaj
Copy link
Contributor Author

pkubaj commented Feb 23, 2021

It looks like this issue is about LLD, not Clang.

Building software with LTO using Clang and linking them with BFD generates proper binaries.

@nemanjai
Copy link
Member

There may very well be assumptions in LLD that ELFv2 implies little endian.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2021

Yeah, looks like some extreme confusion going on. For some reason main is in .opd, and it's jumping to it.

It feels to me that there must be some vestigal ELFv1 code in lld that got missed during the ELFv1 removal kicking in.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2021

Looks like at the very least llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp needs fixed. I don't know if that has anything to do with the LTO issue though.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2021

Yeah, I suspect that might be where the problem is -- when it's ingesting the object file again, it might be injecting function descriptors...

I think what it should be doing there is only kicking in if Obj->getPlatformFlags() != 0x2 or similar.

@adalava
Copy link
Mannequin

adalava mannequin commented Sep 8, 2021

With e3cbf1d I get these warnings on powerpc64 BE target:

$ ~/source/llvm-project/build/bin/clang -target powerpc64-unknown-freebsd13 -flto 47353-test.c
'-isa-v207-instructions' is not a recognized feature for this target (ignoring feature)
'-privileged' is not a recognized feature for this target (ignoring feature)
'-rop-protect' is not a recognized feature for this target (ignoring feature)
'-isa-v207-instructions' is not a recognized feature for this target (ignoring feature)
'-privileged' is not a recognized feature for this target (ignoring feature)
'-rop-protect' is not a recognized feature for this target (ignoring feature)

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@pkubaj
Copy link
Contributor Author

pkubaj commented Feb 21, 2023

Fixed in 4b09cb2.

@pkubaj pkubaj closed this as completed Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld:ELF
Projects
None yet
Development

No branches or pull requests

3 participants