Matthias Braun 850d53a197 LTO: Decide upfront whether to use opaque/non-opaque pointer types
LTO code may end up mixing bitcode files from various sources varying in
their use of opaque pointer types. The current strategy to decide
between opaque / typed pointers upon the first bitcode file loaded does
not work here, since we could be loading a non-opaque bitcode file first
and would then be unable to load any files with opaque pointer types
later.

So for LTO this:
- Adds an `lto::Config::OpaquePointer` option and enforces an upfront
  decision between the two modes.
- Adds `-opaque-pointers`/`-no-opaque-pointers` options to the gold
  plugin; disabled by default.
- `--opaque-pointers`/`--no-opaque-pointers` options with
  `-plugin-opt=-opaque-pointers`/`-plugin-opt=-no-opaque-pointers`
  aliases to lld; disabled by default.
- Adds an `-lto-opaque-pointers` option to the `llvm-lto2` tool.
- Changes the clang driver to pass `-plugin-opt=-opaque-pointers` to
  the linker in LTO modes when clang was configured with opaque
  pointers enabled by default.

This fixes https://github.com/llvm/llvm-project/issues/55377

Differential Revision: https://reviews.llvm.org/D125847
2022-06-01 18:05:53 -07:00

87 lines
2.3 KiB
LLVM

; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/comdat.ll -o %t2.o
; RUN: llvm-lto2 run -save-temps -o %t3.o %t.o %t2.o \
; RUN: -r=%t.o,f1,plx \
; RUN: -r=%t.o,v1,px \
; RUN: -r=%t.o,r11,px \
; RUN: -r=%t.o,r12,px \
; RUN: -r=%t.o,a11,px \
; RUN: -r=%t.o,a12,px \
; RUN: -r=%t.o,a13,px \
; RUN: -r=%t.o,a14,px \
; RUN: -r=%t.o,a15,px \
; RUN: -r=%t2.o,f1,l \
; RUN: -r=%t2.o,will_be_undefined, \
; RUN: -r=%t2.o,v1, \
; RUN: -r=%t2.o,r21,px \
; RUN: -r=%t2.o,r22,px \
; RUN: -r=%t2.o,a21,px \
; RUN: -r=%t2.o,a22,px \
; RUN: -r=%t2.o,a23,px \
; RUN: -r=%t2.o,a24,px \
; RUN: -r=%t2.o,a25,px
; RUN: llvm-dis %t3.o.0.2.internalize.bc -o - | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
$c1 = comdat any
@v1 = weak_odr global i32 42, comdat($c1)
define weak_odr i32 @f1(i8*) comdat($c1) {
bb10:
br label %bb11
bb11:
ret i32 42
}
@r11 = global i32* @v1
@r12 = global i32 (i8*)* @f1
@a11 = alias i32, i32* @v1
@a12 = alias i16, bitcast (i32* @v1 to i16*)
@a13 = alias i32 (i8*), i32 (i8*)* @f1
@a14 = alias i16, bitcast (i32 (i8*)* @f1 to i16*)
@a15 = alias i16, i16* @a14
; CHECK: $c1 = comdat any
; CHECK: $c2 = comdat any
; CHECK-DAG: @v1 = weak_odr global i32 42, comdat($c1)
; CHECK-DAG: @r11 = global ptr @v1{{$}}
; CHECK-DAG: @r12 = global ptr @f1{{$}}
; CHECK-DAG: @r21 = global ptr @v1{{$}}
; CHECK-DAG: @r22 = global ptr @f1{{$}}
; CHECK-DAG: @v1.1 = internal global i32 41, comdat($c2)
; CHECK-DAG: @a11 = alias i32, ptr @v1{{$}}
; CHECK-DAG: @a12 = alias i16, ptr @v1{{$}}
; CHECK-DAG: @a13 = alias i32 (ptr), ptr @f1{{$}}
; CHECK-DAG: @a14 = alias i16, ptr @f1{{$}}
; CHECK-DAG: @a21 = alias i32, ptr @v1.1{{$}}
; CHECK-DAG: @a22 = alias i16, ptr @v1.1{{$}}
; CHECK-DAG: @a23 = alias i32 (ptr), ptr @f1.2{{$}}
; CHECK-DAG: @a24 = alias i16, ptr @f1.2{{$}}
; CHECK: define weak_odr dso_local i32 @f1(ptr %0) comdat($c1) {
; CHECK-NEXT: bb10:
; CHECK-NEXT: br label %bb11{{$}}
; CHECK: bb11:
; CHECK-NEXT: ret i32 42
; CHECK-NEXT: }
; CHECK: define internal i32 @f1.2(ptr %this) comdat($c2) {
; CHECK-NEXT: bb20:
; CHECK-NEXT: store ptr %this, ptr null
; CHECK-NEXT: br label %bb21
; CHECK: bb21:
; CHECK-NEXT: ret i32 41
; CHECK-NEXT: }