Skip to content

clang -flto=thin incompatible with -Wl,-plugin-opt=-lto-embed-bit=optimized  #86946

Open
@chibinz

Description

@chibinz

Hi,

I was trying to obtain whole program bitcode through lto but run into some issues. Here's the step to reproduce.

Running

clang -c -flto=thin hello.c
clang -c -flto=thin foo.c
clang -flto=thin -fuse-ld=lld -Wl,-plugin-opt=-lto-embed-bitcode=optimized hello.o foo.o -o hello
objcopy --dump-section .llvmbc=hello.bc hello
clang hello.bc

gives the following error

error: Invalid encoding
1 error generated.

This issue does not occur when using -flto=full. The rust compiler also reports similar issues here: rust-lang/rust#84395

hello.c

#include <stdio.h>

extern void foo();

int main() {
    printf("Hello, world!\n");
    foo();
    return 0;
}

foo.c

#include <stdio.h>

void foo() {
    printf("foo!\n");
}

clang version:

clang version 16.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    LTOLink time optimization (regular/full LTO or ThinLTO)questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions