Skip to content

Commit ce24b19

Browse files
committed
[lld-macho] Generate test bodies for icf-safe-thunk tests
1 parent 3bef742 commit ce24b19

File tree

2 files changed

+175
-231
lines changed

2 files changed

+175
-231
lines changed
Lines changed: 67 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,103 @@
11
; REQUIRES: aarch64
22

3-
;;; Build the
4-
; RUN: rm -rf %t; mkdir %t
5-
; RUN: llc -filetype=obj %s -O3 -o %t/icf-obj-safe-thunks-dwarf.o -enable-machine-outliner=never -mtriple arm64-apple-macos -addrsig
6-
; RUN: %lld -arch arm64 -lSystem --icf=safe_thunks -dylib -o %t/icf-safe-dwarf.dylib %t/icf-obj-safe-thunks-dwarf.o
3+
; RUN: rm -rf %t && split-file %s %t
4+
5+
; RUN: llc -filetype=obj %t/a.ll -O3 -o %t/a.o -enable-machine-outliner=never -mtriple arm64-apple-macos -addrsig
6+
; RUN: %lld -arch arm64 -lSystem --icf=safe_thunks -dylib -o %t/a.dylib %t/a.o
77

88
;;; Check that we generate valid dSYM
9-
; RUN: dsymutil %t/icf-safe-dwarf.dylib -o %t/icf-safe.dSYM
10-
; RUN: llvm-dwarfdump --verify %t/icf-safe.dSYM | FileCheck %s --check-prefix=VERIFY-DSYM
9+
; RUN: dsymutil %t/a.dylib -o %t/a.dSYM
10+
; RUN: llvm-dwarfdump --verify %t/a.dSYM | FileCheck %s --check-prefix=VERIFY-DSYM
1111
; VERIFY-DSYM: No errors.
1212

1313
;;; Check that we don't generate STABS entries (N_FUN) for ICF'ed function thunks
14-
; RUN: dsymutil -s %t/icf-safe-dwarf.dylib | FileCheck %s --check-prefix=VERIFY-STABS
14+
; RUN: dsymutil -s %t/a.dylib | FileCheck %s --check-prefix=VERIFY-STABS
1515
; VERIFY-STABS-NOT: N_FUN{{.*}}_func_B
1616
; VERIFY-STABS-NOT: N_FUN{{.*}}_func_C
1717

1818
;;; Check that we do generate STABS entries (N_FUN) for non-ICF'ed functions
1919
; VERIFY-STABS: N_FUN{{.*}}_func_A
2020
; VERIFY-STABS: N_FUN{{.*}}_take_func_addr
2121

22+
;--- a.cpp
23+
#define ATTR __attribute__((noinline)) extern "C"
24+
typedef unsigned long long ULL;
25+
26+
ATTR int func_A() { return 1; }
27+
ATTR int func_B() { return 1; }
28+
ATTR int func_C() { return 1; }
29+
30+
ATTR ULL take_func_addr() {
31+
ULL val = 0;
32+
val += (ULL)(void*)func_A;
33+
val += (ULL)(void*)func_B;
34+
val += (ULL)(void*)func_C;
35+
return val;
36+
}
37+
38+
;--- gen
39+
clang -target arm64-apple-macos11.0 -S -emit-llvm a.cpp -O3 -g -o -
2240

23-
; ModuleID = 'icf-safe-thunks-dwarf.cpp'
24-
source_filename = "icf-safe-thunks-dwarf.cpp"
41+
;--- a.ll
42+
; ModuleID = 'a.cpp'
43+
source_filename = "a.cpp"
2544
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
2645
target triple = "arm64-apple-macosx11.0.0"
2746

28-
; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
29-
define i32 @func_A() #0 !dbg !13 {
30-
entry:
31-
ret i32 1
47+
; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind ssp willreturn memory(none) uwtable(sync)
48+
define noundef i32 @func_A() #0 !dbg !12 {
49+
ret i32 1, !dbg !16
3250
}
3351

34-
; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
35-
define i32 @func_B() #0 !dbg !18 {
36-
entry:
37-
ret i32 1
52+
; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind ssp willreturn memory(none) uwtable(sync)
53+
define noundef i32 @func_B() #0 !dbg !17 {
54+
ret i32 1, !dbg !18
3855
}
3956

40-
; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
41-
define i32 @func_C() #0 !dbg !20 {
42-
entry:
43-
ret i32 1
57+
; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind ssp willreturn memory(none) uwtable(sync)
58+
define noundef i32 @func_C() #0 !dbg !19 {
59+
ret i32 1, !dbg !20
4460
}
4561

46-
; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
47-
define i64 @take_func_addr() #0 !dbg !22 {
48-
entry:
49-
%val = alloca i64, align 8
50-
store i64 0, ptr %val, align 8
51-
%0 = load i64, ptr %val, align 8
52-
%add = add i64 %0, ptrtoint (ptr @func_A to i64)
53-
store i64 %add, ptr %val, align 8
54-
%1 = load i64, ptr %val, align 8
55-
%add1 = add i64 %1, ptrtoint (ptr @func_B to i64)
56-
store i64 %add1, ptr %val, align 8
57-
%2 = load i64, ptr %val, align 8
58-
%add2 = add i64 %2, ptrtoint (ptr @func_C to i64)
59-
store i64 %add2, ptr %val, align 8
60-
%3 = load i64, ptr %val, align 8
61-
ret i64 %3
62+
; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind ssp willreturn memory(none) uwtable(sync)
63+
define noundef i64 @take_func_addr() local_unnamed_addr #0 !dbg !21 {
64+
#dbg_value(i64 0, !25, !DIExpression(), !26)
65+
#dbg_value(i64 ptrtoint (ptr @func_A to i64), !25, !DIExpression(), !26)
66+
#dbg_value(i64 add (i64 ptrtoint (ptr @func_A to i64), i64 ptrtoint (ptr @func_B to i64)), !25, !DIExpression(), !26)
67+
#dbg_value(i64 add (i64 add (i64 ptrtoint (ptr @func_A to i64), i64 ptrtoint (ptr @func_B to i64)), i64 ptrtoint (ptr @func_C to i64)), !25, !DIExpression(), !26)
68+
ret i64 add (i64 add (i64 ptrtoint (ptr @func_A to i64), i64 ptrtoint (ptr @func_B to i64)), i64 ptrtoint (ptr @func_C to i64)), !dbg !27
6269
}
6370

64-
attributes #0 = { noinline nounwind }
71+
attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind ssp willreturn memory(none) uwtable(sync) "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+altnzcv,+ccdp,+ccidx,+complxnum,+crc,+dit,+dotprod,+flagm,+fp-armv8,+fp16fml,+fptoint,+fullfp16,+jsconv,+lse,+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+specrestrict,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a,+zcm,+zcz" }
6572

6673
!llvm.dbg.cu = !{!0}
6774
!llvm.module.flags = !{!6, !7, !8, !9, !10, !11}
68-
!llvm.ident = !{!12}
6975

70-
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
71-
!1 = !DIFile(filename: "icf-safe-thunks-dwarf.cpp", directory: "/tmp/test")
76+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
77+
!1 = !DIFile(filename: "a.cpp", directory: "/proc/self/cwd")
78+
!2 = !{!3, !5}
79+
!3 = !DIDerivedType(tag: DW_TAG_typedef, name: "ULL", file: !1, line: 2, baseType: !4)
80+
!4 = !DIBasicType(name: "unsigned long long", size: 64, encoding: DW_ATE_unsigned)
81+
!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
7282
!6 = !{i32 7, !"Dwarf Version", i32 4}
7383
!7 = !{i32 2, !"Debug Info Version", i32 3}
7484
!8 = !{i32 1, !"wchar_size", i32 4}
7585
!9 = !{i32 8, !"PIC Level", i32 2}
7686
!10 = !{i32 7, !"uwtable", i32 1}
7787
!11 = !{i32 7, !"frame-pointer", i32 1}
78-
!12 = !{!"clang version 20.0.0"}
79-
!13 = distinct !DISubprogram(name: "func_A", scope: !1, file: !1, line: 4, type: !14, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
80-
!14 = !DISubroutineType(types: !15)
81-
!15 = !{}
82-
!18 = distinct !DISubprogram(name: "func_B", scope: !1, file: !1, line: 5, type: !14, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
83-
!20 = distinct !DISubprogram(name: "func_C", scope: !1, file: !1, line: 6, type: !14, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
84-
!22 = distinct !DISubprogram(name: "take_func_addr", scope: !1, file: !1, line: 8, type: !14, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
85-
86-
87-
88-
89-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90-
;;;;;;;;;;;;;; Generate the above LLVM IR with the below script ;;;;;;;;;;;;;;;
91-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
92-
; #!/bin/bash
93-
; set -ex
94-
; TOOLCHAIN_BIN="llvm-project/build/Debug/bin"
95-
;
96-
; # Create icf-safe-thunks-dwarf.cpp file
97-
; cat > icf-safe-thunks-dwarf.cpp <<EOF
98-
; #define ATTR __attribute__((noinline)) extern "C"
99-
; typedef unsigned long long ULL;
100-
;
101-
; ATTR int func_A() { return 1; }
102-
; ATTR int func_B() { return 1; }
103-
; ATTR int func_C() { return 1; }
104-
;
105-
; ATTR ULL take_func_addr() {
106-
; ULL val = 0;
107-
; val += (ULL)(void*)func_A;
108-
; val += (ULL)(void*)func_B;
109-
; val += (ULL)(void*)func_C;
110-
; return val;
111-
; }
112-
; EOF
113-
;
114-
; $TOOLCHAIN_BIN/clang -target arm64-apple-macos11.0 -S -emit-llvm -g \
115-
; icf-safe-thunks-dwarf.cpp
88+
!12 = distinct !DISubprogram(name: "func_A", scope: !1, file: !1, line: 4, type: !13, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
89+
!13 = !DISubroutineType(types: !14)
90+
!14 = !{!15}
91+
!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
92+
!16 = !DILocation(line: 4, column: 21, scope: !12)
93+
!17 = distinct !DISubprogram(name: "func_B", scope: !1, file: !1, line: 5, type: !13, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
94+
!18 = !DILocation(line: 5, column: 21, scope: !17)
95+
!19 = distinct !DISubprogram(name: "func_C", scope: !1, file: !1, line: 6, type: !13, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
96+
!20 = !DILocation(line: 6, column: 21, scope: !19)
97+
!21 = distinct !DISubprogram(name: "take_func_addr", scope: !1, file: !1, line: 8, type: !22, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !24)
98+
!22 = !DISubroutineType(types: !23)
99+
!23 = !{!3}
100+
!24 = !{!25}
101+
!25 = !DILocalVariable(name: "val", scope: !21, file: !1, line: 9, type: !3)
102+
!26 = !DILocation(line: 0, scope: !21)
103+
!27 = !DILocation(line: 13, column: 5, scope: !21)

0 commit comments

Comments
 (0)