Skip to content

Commit acdc608

Browse files
committed
[llvm-ifs][IFS] llvm Interface Stubs merging + object file generation tool.
This tool merges interface stub files to produce a merged interface stub file or a stub library. Currently it for stub library generation it can produce an ELF .so stub file, or a TBD file (experimental). It will be used by the clang -emit-interface-stubs compilation pipeline to merge and assemble the per-CU stub files into a stub library. The new IFS format is as follows: --- !experimental-ifs-v1 IfsVersion: 1.0 Triple: <llvm triple> ObjectFileFormat: <ELF | TBD> Symbols: _ZSymbolName: { Type: <type>, etc... } ... Differential Revision: https://reviews.llvm.org/D66405 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370499 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a3c7b08 commit acdc608

17 files changed

+793
-1
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ set(LLVM_TEST_DEPENDS
6969
llvm-exegesis
7070
llvm-extract
7171
llvm-isel-fuzzer
72+
llvm-ifs
7273
llvm-jitlink
7374
llvm-lib
7475
llvm-link

test/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def get_asan_rtlib():
142142
'dsymutil', 'lli', 'lli-child-target', 'llvm-ar', 'llvm-as',
143143
'llvm-bcanalyzer', 'llvm-config', 'llvm-cov', 'llvm-cxxdump', 'llvm-cvtres',
144144
'llvm-diff', 'llvm-dis', 'llvm-dwarfdump', 'llvm-exegesis', 'llvm-extract',
145-
'llvm-isel-fuzzer', 'llvm-jitlink', 'llvm-opt-fuzzer', 'llvm-lib',
145+
'llvm-isel-fuzzer', 'llvm-ifs', 'llvm-jitlink', 'llvm-opt-fuzzer', 'llvm-lib',
146146
'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mca',
147147
'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump',
148148
'llvm-pdbutil', 'llvm-profdata', 'llvm-ranlib', 'llvm-rc', 'llvm-readelf',
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# RUN: not llvm-ifs -action write-ifs -o - %s %S/object.ifs 2>&1 | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# CHECK-IFS: error: Interface Stub: ObjectFileFormat Mismatch.
5+
# CHECK-IFS-NEXT: Filenames:
6+
# CHECK-IFS-NEXT: ObjectFileFormat Values: TBD ELF
7+
8+
--- !experimental-ifs-v1
9+
IfsVersion: 1.0
10+
Triple: x86_64-apple-unknown
11+
ObjectFileFormat: TBD
12+
Symbols:
13+
a: { Type: Func }
14+
...
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# RUN: not llvm-ifs -action write-ifs -o - %s %S/object.ifs 2>&1 | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# CHECK-IFS: error: Interface Stub: Triple Mismatch.
5+
# CHECK-IFS-NEXT: Filenames:
6+
# CHECK-IFS-NEXT: Triple Values: mips-unknown-linux x86_64-unknown-linux-gnu
7+
8+
--- !experimental-ifs-v1
9+
IfsVersion: 1.0
10+
Triple: mips-unknown-linux
11+
ObjectFileFormat: ELF
12+
Symbols:
13+
a: { Type: Func }
14+
...
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RUN: not llvm-ifs -action write-ifs -o - %s %S/object.ifs 2>&1 | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# RUN: not llvm-ifs -action write-ifs -o - %s 2>&1 | \
5+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS2
6+
7+
# CHECK-IFS: error: Interface Stub: IfsVersion Mismatch.
8+
# CHECK-IFS2: error: Interface Stub: Bad IfsVersion: 0.0, llvm-ifs supported version: 1.2.
9+
10+
--- !experimental-ifs-v1
11+
IfsVersion: 0.0
12+
Triple: x86_64-unknown-linux-gnu
13+
ObjectFileFormat: ELF
14+
Symbols:
15+
a: { Type: Func }
16+
...

test/tools/llvm-ifs/conflict-size.ifs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RUN: not llvm-ifs -action write-ifs -o - %s %S/object.ifs 2>&1 | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# Here we are testing to see if two symbols with identical names will fail to
5+
# merge in conflict due to mismatching sizes.
6+
# CHECK-IFS: error: Interface Stub: Size Mismatch for b.
7+
# CHECK-IFS-NEXT: Filename:
8+
# CHECK-IFS-NEXT: Size Values: 1 4
9+
10+
--- !experimental-ifs-v1
11+
IfsVersion: 1.0
12+
Triple: x86_64-unknown-linux-gnu
13+
ObjectFileFormat: ELF
14+
Symbols:
15+
b: { Type: Object, Size: 1 }
16+
...

test/tools/llvm-ifs/conflict-type.ifs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RUN: not llvm-ifs -action write-ifs -o - %s %S/func.ifs 2>&1 | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# Here we are testing to see if two symbols with identical names will fail to
5+
# merge in conflict due to mismatched types.
6+
# CHECK-IFS: error: Interface Stub: Type Mismatch for a.
7+
# CHECK-IFS-NEXT: Filename:
8+
# CHECK-IFS-NEXT: Type Values: Object Func
9+
10+
--- !experimental-ifs-v1
11+
IfsVersion: 1.0
12+
Triple: x86_64-unknown-linux-gnu
13+
ObjectFileFormat: ELF
14+
Symbols:
15+
a: { Type: Object, Size: 1 }
16+
...

test/tools/llvm-ifs/conflict-weak.ifs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# RUN: not llvm-ifs -action write-ifs -o - %s %S/func.ifs 2>&1 | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# Here we are testing to see if two symbols with identical names will fail to
5+
# merge in conflict due to one being weak and one not. Eventually this will work
6+
# when llvm-ifs has support for resolving these kinds of conflicts.
7+
# CHECK-IFS: error: Interface Stub: Weak Mismatch for a.
8+
# CHECK-IFS-NEXT: Filename:
9+
# CHECK-IFS-NEXT: Weak Values: 1 0
10+
11+
--- !experimental-ifs-v1
12+
IfsVersion: 1.0
13+
Triple: x86_64-unknown-linux-gnu
14+
ObjectFileFormat: ELF
15+
Symbols:
16+
a: { Type: Func, Weak: true }
17+
...

test/tools/llvm-ifs/func.ifs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# RUN: llvm-ifs -action write-ifs -o - %s %S/object.ifs | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# RUN: llvm-ifs -action write-bin -o - %s %S/object.ifs | \
5+
# RUN: llvm-readelf --all | FileCheck %s --check-prefixes=CHECK-ELF
6+
7+
# RUN: llvm-ifs -action write-bin -force-format TBD -o - %s %S/object.ifs | \
8+
# RUN: FileCheck %s --check-prefixes=CHECK-DARWIN-TBD3
9+
10+
# RUN: llvm-ifs -action write-ifs -o - %s %s | \
11+
# RUN: FileCheck %s --check-prefixes=CHECK-MERGE-IFS
12+
13+
# CHECK-IFS: --- !experimental-ifs-v1
14+
# CHECK-IFS-NEXT: IfsVersion: 1.0
15+
# CHECK-IFS-NEXT: Triple: x86_64-unknown-linux-gnu
16+
# CHECK-IFS-NEXT: ObjectFileFormat: ELF
17+
# CHECK-IFS-NEXT: Symbols:
18+
# CHECK-IFS-DAG: a: { Type: Func }
19+
# CHECK-IFS-DAG: b: { Type: Object, Size: 4 }
20+
# CHECK-IFS: ...
21+
22+
# CHECK-ELF: ELF Header:
23+
# CHECK-ELF: Class: ELF64
24+
# CHECK-ELF: Type: DYN (Shared object file)
25+
# CHECK-ELF: FUNC GLOBAL DEFAULT 1 a
26+
# CHECK-ELF: OBJECT GLOBAL DEFAULT 1 b
27+
28+
# CHECK-DARWIN-TBD3: --- !tapi-tbd-v3
29+
# CHECK-DARWIN-TBD3-NEXT: archs: [ x86_64 ]
30+
# CHECK-DARWIN-TBD3-NEXT: platform: macosx
31+
# CHECK-DARWIN-TBD3-NEXT: flags: [ flat_namespace, not_app_extension_safe ]
32+
# CHECK-DARWIN-TBD3-NEXT: install-name: ''
33+
# CHECK-DARWIN-TBD3-NEXT: current-version: 0
34+
# CHECK-DARWIN-TBD3-NEXT: compatibility-version: 0
35+
# CHECK-DARWIN-TBD3-NEXT: objc-constraint: none
36+
# CHECK-DARWIN-TBD3-NEXT: exports:
37+
# CHECK-DARWIN-TBD3-NEXT: - archs: [ x86_64 ]
38+
# CHECK-DARWIN-TBD3-NEXT: symbols: [ a, b ]
39+
# CHECK-DARWIN-TBD3-NEXT: ...
40+
41+
# Here we are testing to see if two identical symbols will merge.
42+
# CHECK-MERGE-IFS: --- !experimental-ifs-v1
43+
# CHECK-MERGE-IFS-NEXT: IfsVersion: 1.0
44+
# CHECK-MERGE-IFS-NEXT: Triple: x86_64-unknown-linux-gnu
45+
# CHECK-MERGE-IFS-NEXT: ObjectFileFormat: ELF
46+
# CHECK-MERGE-IFS-NEXT: Symbols:
47+
# CHECK-MERGE-IFS-NEXT: a: { Type: Func }
48+
# CHECK-MERGE-IFS-NEXT: ...
49+
50+
--- !experimental-ifs-v1
51+
IfsVersion: 1.0
52+
Triple: x86_64-unknown-linux-gnu
53+
ObjectFileFormat: ELF
54+
Symbols:
55+
a: { Type: Func }
56+
...
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# RUN: llvm-ifs -action write-ifs -o - %s %S/func.ifs %S/object.ifs %S/weak.ifs | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# RUN: llvm-ifs -action write-bin -o - %s %S/func.ifs %S/object.ifs %S/weak.ifs | \
5+
# RUN: llvm-readelf --all | FileCheck %s --check-prefixes=CHECK-ELF
6+
7+
# CHECK-IFS: --- !experimental-ifs-v1
8+
# CHECK-IFS-NEXT: IfsVersion: 1.0
9+
# CHECK-IFS-NEXT: Triple: x86_64-unknown-linux-gnu
10+
# CHECK-IFS-NEXT: ObjectFileFormat: ELF
11+
# CHECK-IFS-NEXT: Symbols:
12+
# CHECK-IFS-DAG: e: { Type: Object, Size: 8 }
13+
# CHECK-IFS-DAG: a: { Type: Func }
14+
# CHECK-IFS-DAG: f: { Type: Object, Size: 2 }
15+
# CHECK-IFS-DAG: _Z10strongFuncv: { Type: Func }
16+
# CHECK-IFS-DAG: _Z8weakFuncv: { Type: Func, Weak: true }
17+
# CHECK-IFS-DAG: b: { Type: Object, Size: 4 }
18+
# CHECK-IFS: ...
19+
20+
# CHECK-ELF: FUNC GLOBAL DEFAULT 1 _Z10strongFuncv
21+
# CHECK-ELF: FUNC WEAK DEFAULT 1 _Z8weakFuncv
22+
# CHECK-ELF: FUNC GLOBAL DEFAULT 1 a
23+
# CHECK-ELF: OBJECT GLOBAL DEFAULT 1 b
24+
# CHECK-ELF: OBJECT GLOBAL DEFAULT 1 e
25+
# CHECK-ELF: OBJECT GLOBAL DEFAULT 1 f
26+
27+
--- !experimental-ifs-v1
28+
IfsVersion: 1.0
29+
Triple: x86_64-unknown-linux-gnu
30+
ObjectFileFormat: ELF
31+
Symbols:
32+
e: { Type: Object, Size: 8 }
33+
f: { Type: Object, Size: 2 }
34+
...

test/tools/llvm-ifs/object.ifs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RUN: llvm-ifs -action write-ifs -o - %s | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
3+
4+
# RUN: llvm-ifs -action write-bin -o - %s | \
5+
# RUN: llvm-readelf --all | FileCheck %s --check-prefixes=CHECK-ELF
6+
7+
# CHECK-IFS: --- !experimental-ifs-v1
8+
# CHECK-IFS-NEXT: IfsVersion: 1.0
9+
# CHECK-IFS-NEXT: Triple: x86_64-unknown-linux-gnu
10+
# CHECK-IFS-NEXT: ObjectFileFormat: ELF
11+
# CHECK-IFS-NEXT: Symbols:
12+
# CHECK-IFS-NEXT: b: { Type: Object, Size: 4 }
13+
# CHECK-IFS-NEXT: ...
14+
15+
# CHECK-ELF: ELF Header:
16+
# CHECK-ELF: Class: ELF64
17+
# CHECK-ELF: Data: 2's complement, little endian
18+
# CHECK-ELF: Type: DYN (Shared object file)
19+
# CHECK-ELF-NOT: FUNC GLOBAL DEFAULT 1 a
20+
# CHECK-ELF: OBJECT GLOBAL DEFAULT 1 b
21+
22+
--- !experimental-ifs-v1
23+
IfsVersion: 1.0
24+
Triple: x86_64-unknown-linux-gnu
25+
ObjectFileFormat: ELF
26+
Symbols:
27+
b: { Type: Object, Size: 4 }
28+
...

test/tools/llvm-ifs/version-ok.ifs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: llvm-ifs -action write-ifs -o - %s %S/object.ifs
2+
3+
--- !experimental-ifs-v1
4+
IfsVersion: 1.1
5+
Triple: x86_64-unknown-linux-gnu
6+
ObjectFileFormat: ELF
7+
Symbols:
8+
a: { Type: Func }
9+
...

test/tools/llvm-ifs/weak.ifs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: llvm-ifs -action write-ifs -o - %s | FileCheck %s --check-prefixes=CHECK-IFS
2+
3+
# CHECK-IFS: --- !experimental-ifs-v1
4+
# CHECK-IFS-NEXT: IfsVersion: 1.0
5+
# CHECK-IFS-NEXT: Triple: x86_64-unknown-linux-gnu
6+
# CHECK-IFS-NEXT: ObjectFileFormat: ELF
7+
# CHECK-IFS-NEXT: Symbols:
8+
# CHECK-IFS-DAG: _Z8weakFuncv: { Type: Func, Weak: true }
9+
# CHECK-IFS-DAG: _Z10strongFuncv: { Type: Func }
10+
# CHECK-IFS: ...
11+
12+
--- !experimental-ifs-v1
13+
IfsVersion: 1.0
14+
Triple: x86_64-unknown-linux-gnu
15+
ObjectFileFormat: ELF
16+
Symbols:
17+
_Z8weakFuncv: { Type: Func, Weak: true }
18+
_Z10strongFuncv: { Type: Func }
19+
...

tools/LLVMBuild.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ subdirectories =
3232
llvm-dwarfdump
3333
llvm-dwp
3434
llvm-elfabi
35+
llvm-ifs
3536
llvm-exegesis
3637
llvm-extract
3738
llvm-jitlistener

tools/llvm-ifs/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(LLVM_LINK_COMPONENTS
2+
Object
3+
Support
4+
TextAPI
5+
ObjectYAML
6+
)
7+
8+
add_llvm_tool(llvm-ifs
9+
llvm-ifs.cpp
10+
)

tools/llvm-ifs/LLVMBuild.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;===- ./tools/llvm-ifs/LLVMBuild.txt ---------------------------*- Conf -*--===;
2+
;
3+
; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
; See https://llvm.org/LICENSE.txt for license information.
5+
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
;
7+
;===------------------------------------------------------------------------===;
8+
;
9+
; This is an LLVMBuild description file for the components in this subdirectory.
10+
;
11+
; For more information on the LLVMBuild system, please see:
12+
;
13+
; http://llvm.org/docs/LLVMBuild.html
14+
;
15+
;===------------------------------------------------------------------------===;
16+
17+
[component_0]
18+
type = Tool
19+
name = llvm-ifs
20+
parent = Tools
21+
required_libraries = Object Support TextAPI

0 commit comments

Comments
 (0)