@@ -2764,15 +2764,14 @@ class DwarfException : public Dwarf {
2764
2764
bool hasCalls;
2765
2765
bool hasLandingPads;
2766
2766
std::vector<MachineMove> Moves;
2767
- Function::LinkageTypes linkage ;
2767
+ const Function * function ;
2768
2768
2769
2769
FunctionEHFrameInfo (const std::string &FN, unsigned Num, unsigned P,
2770
2770
bool hC, bool hL,
2771
2771
const std::vector<MachineMove> &M,
2772
- Function::LinkageTypes l ):
2772
+ const Function *f ):
2773
2773
FnName (FN), Number(Num), PersonalityIndex(P),
2774
- hasCalls (hC), hasLandingPads(hL), Moves(M),
2775
- linkage (l) { }
2774
+ hasCalls (hC), hasLandingPads(hL), Moves(M), function (f) { }
2776
2775
};
2777
2776
2778
2777
std::vector<FunctionEHFrameInfo> EHFrames;
@@ -2869,32 +2868,39 @@ class DwarfException : public Dwarf {
2869
2868
// / EmitEHFrame - Emit function exception frame information.
2870
2869
// /
2871
2870
void EmitEHFrame (const FunctionEHFrameInfo &EHFrameInfo) {
2871
+ Function::LinkageTypes linkage = EHFrameInfo.function ->getLinkage ();
2872
+
2872
2873
Asm->SwitchToTextSection (TAI->getDwarfEHFrameSection ());
2873
2874
2874
2875
// Externally visible entry into the functions eh frame info.
2875
2876
// If the corresponding function is static, this should not be
2876
2877
// externally visible.
2877
- if (EHFrameInfo. linkage != Function::InternalLinkage) {
2878
+ if (linkage != Function::InternalLinkage) {
2878
2879
if (const char *GlobalEHDirective = TAI->getGlobalEHDirective ())
2879
2880
O << GlobalEHDirective << EHFrameInfo.FnName << " \n " ;
2880
2881
}
2881
2882
2882
2883
// If corresponding function is weak definition, this should be too.
2883
- if ((EHFrameInfo. linkage == Function::WeakLinkage ||
2884
- EHFrameInfo. linkage == Function::LinkOnceLinkage) &&
2884
+ if ((linkage == Function::WeakLinkage ||
2885
+ linkage == Function::LinkOnceLinkage) &&
2885
2886
TAI->getWeakDefDirective ())
2886
2887
O << TAI->getWeakDefDirective () << EHFrameInfo.FnName << " \n " ;
2887
2888
2888
2889
// If there are no calls then you can't unwind. This may mean we can
2889
2890
// omit the EH Frame, but some environments do not handle weak absolute
2890
2891
// symbols.
2891
2892
if (!EHFrameInfo.hasCalls &&
2892
- ((EHFrameInfo. linkage != Function::WeakLinkage &&
2893
- EHFrameInfo. linkage != Function::LinkOnceLinkage) ||
2893
+ ((linkage != Function::WeakLinkage &&
2894
+ linkage != Function::LinkOnceLinkage) ||
2894
2895
!TAI->getWeakDefDirective () ||
2895
2896
TAI->getSupportsWeakOmittedEHFrame ()))
2896
2897
{
2897
2898
O << EHFrameInfo.FnName << " = 0\n " ;
2899
+ // This name has no connection to the function, so it might get
2900
+ // dead-stripped when the function is not, erroneously. Prohibit
2901
+ // dead-stripping unconditionally.
2902
+ if (const char *UsedDirective = TAI->getUsedDirective ())
2903
+ O << UsedDirective << EHFrameInfo.FnName << " \n\n " ;
2898
2904
} else {
2899
2905
O << EHFrameInfo.FnName << " :\n " ;
2900
2906
@@ -2941,10 +2947,16 @@ class DwarfException : public Dwarf {
2941
2947
2942
2948
Asm->EmitAlignment (2 );
2943
2949
EmitLabel (" eh_frame_end" , EHFrameInfo.Number );
2944
- }
2945
2950
2946
- if (const char *UsedDirective = TAI->getUsedDirective ())
2947
- O << UsedDirective << EHFrameInfo.FnName << " \n\n " ;
2951
+ // If the function is marked used, this table should be also. We cannot
2952
+ // make the mark unconditional in this case, since retaining the table
2953
+ // also retains the function in this case, and there is code around
2954
+ // that depends on unused functions (calling undefined externals) being
2955
+ // dead-stripped to link correctly. Yes, there really is.
2956
+ if (MMI->getUsedFunctions ().count (EHFrameInfo.function ))
2957
+ if (const char *UsedDirective = TAI->getUsedDirective ())
2958
+ O << UsedDirective << EHFrameInfo.FnName << " \n\n " ;
2959
+ }
2948
2960
}
2949
2961
2950
2962
// / EmitExceptionTable - Emit landing pads and actions.
@@ -3414,7 +3426,7 @@ class DwarfException : public Dwarf {
3414
3426
MF->getFrameInfo ()->hasCalls (),
3415
3427
!MMI->getLandingPads ().empty (),
3416
3428
MMI->getFrameMoves (),
3417
- MF->getFunction ()-> getLinkage () ));
3429
+ MF->getFunction ()));
3418
3430
}
3419
3431
};
3420
3432
0 commit comments