@@ -763,6 +763,25 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
763
763
return NextUniqueID++;
764
764
}
765
765
766
+ static std::tuple<StringRef, bool , unsigned >
767
+ getGlobalObjectInfo (const GlobalObject *GO, const TargetMachine &TM) {
768
+ StringRef Group = " " ;
769
+ bool IsComdat = false ;
770
+ unsigned Flags = 0 ;
771
+ if (const Comdat *C = getELFComdat (GO)) {
772
+ Flags |= ELF::SHF_GROUP;
773
+ Group = C->getName ();
774
+ IsComdat = C->getSelectionKind () == Comdat::Any;
775
+ }
776
+ if (auto *GV = dyn_cast<GlobalVariable>(GO)) {
777
+ if (TM.isLargeData (GV)) {
778
+ assert (TM.getTargetTriple ().getArch () == Triple::x86_64);
779
+ Flags |= ELF::SHF_X86_64_LARGE;
780
+ }
781
+ }
782
+ return {Group, IsComdat, Flags};
783
+ }
784
+
766
785
static MCSection *selectExplicitSectionGlobal (
767
786
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
768
787
MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
@@ -793,14 +812,9 @@ static MCSection *selectExplicitSectionGlobal(
793
812
// Infer section flags from the section name if we can.
794
813
Kind = getELFKindForNamedSection (SectionName, Kind);
795
814
796
- StringRef Group = " " ;
797
- bool IsComdat = false ;
798
815
unsigned Flags = getELFSectionFlags (Kind);
799
- if (const Comdat *C = getELFComdat (GO)) {
800
- Group = C->getName ();
801
- IsComdat = C->getSelectionKind () == Comdat::Any;
802
- Flags |= ELF::SHF_GROUP;
803
- }
816
+ auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo (GO, TM);
817
+ Flags |= ExtraFlags;
804
818
805
819
unsigned EntrySize = getEntrySizeForKind (Kind);
806
820
const unsigned UniqueID = calcUniqueIDUpdateFlagsAndSize (
@@ -848,19 +862,8 @@ static MCSectionELF *selectELFSectionForGlobal(
848
862
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
849
863
unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
850
864
851
- StringRef Group = " " ;
852
- bool IsComdat = false ;
853
- if (const Comdat *C = getELFComdat (GO)) {
854
- Flags |= ELF::SHF_GROUP;
855
- Group = C->getName ();
856
- IsComdat = C->getSelectionKind () == Comdat::Any;
857
- }
858
- if (auto *GV = dyn_cast<GlobalVariable>(GO)) {
859
- if (TM.isLargeData (GV)) {
860
- assert (TM.getTargetTriple ().getArch () == Triple::x86_64);
861
- Flags |= ELF::SHF_X86_64_LARGE;
862
- }
863
- }
865
+ auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo (GO, TM);
866
+ Flags |= ExtraFlags;
864
867
865
868
// Get the section entry size based on the kind.
866
869
unsigned EntrySize = getEntrySizeForKind (Kind);
0 commit comments