@@ -763,6 +763,25 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
763763 return NextUniqueID++;
764764}
765765
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+
766785static MCSection *selectExplicitSectionGlobal (
767786 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
768787 MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
@@ -793,14 +812,9 @@ static MCSection *selectExplicitSectionGlobal(
793812 // Infer section flags from the section name if we can.
794813 Kind = getELFKindForNamedSection (SectionName, Kind);
795814
796- StringRef Group = " " ;
797- bool IsComdat = false ;
798815 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;
804818
805819 unsigned EntrySize = getEntrySizeForKind (Kind);
806820 const unsigned UniqueID = calcUniqueIDUpdateFlagsAndSize (
@@ -848,19 +862,8 @@ static MCSectionELF *selectELFSectionForGlobal(
848862 const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
849863 unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
850864
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;
864867
865868 // Get the section entry size based on the kind.
866869 unsigned EntrySize = getEntrySizeForKind (Kind);
0 commit comments