@@ -232,8 +232,9 @@ const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
232232 MMI, Streamer);
233233}
234234
235- static SectionKind getELFKindForNamedSection (StringRef Name, SectionKind K) {
236- // N.B.: The defaults used in here are not the same ones used in MC.
235+ static SectionKind getELFKindForNamedSection (StringRef Name, SectionKind K,
236+ const Triple &TargetTriple) {
237+ // N.B.: The defaults used in here are no the same ones used in MC.
237238 // We follow gcc, MC follows gas. For example, given ".section .eh_frame",
238239 // both gas and MC will produce a section with no flags. Given
239240 // section(".eh_frame") gcc will produce:
@@ -264,6 +265,7 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
264265 return SectionKind::getThreadData ();
265266
266267 if (Name == " .tbss" ||
268+ (TargetTriple.isAndroid () && Name == " .tcommon" ) || // LDC
267269 Name.startswith (" .tbss." ) ||
268270 Name.startswith (" .gnu.linkonce.tb." ) ||
269271 Name.startswith (" .llvm.linkonce.tb." ))
@@ -294,7 +296,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
294296 return ELF::SHT_PROGBITS;
295297}
296298
297- static unsigned getELFSectionFlags (SectionKind K) {
299+ static unsigned getELFSectionFlags (SectionKind K, const Triple &TargetTriple ) {
298300 unsigned Flags = 0 ;
299301
300302 if (!K.isMetadata ())
@@ -309,7 +311,7 @@ static unsigned getELFSectionFlags(SectionKind K) {
309311 if (K.isWriteable ())
310312 Flags |= ELF::SHF_WRITE;
311313
312- if (K.isThreadLocal ())
314+ if (K.isThreadLocal () && !TargetTriple. isAndroid ()) // LDC
313315 Flags |= ELF::SHF_TLS;
314316
315317 if (K.isMergeableCString () || K.isMergeableConst ())
@@ -375,10 +377,10 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
375377 }
376378
377379 // Infer section flags from the section name if we can.
378- Kind = getELFKindForNamedSection (SectionName, Kind);
380+ Kind = getELFKindForNamedSection (SectionName, Kind, getTargetTriple () );
379381
380382 StringRef Group = " " ;
381- unsigned Flags = getELFSectionFlags (Kind);
383+ unsigned Flags = getELFSectionFlags (Kind, getTargetTriple () );
382384 if (const Comdat *C = getELFComdat (GO)) {
383385 Group = C->getName ();
384386 Flags |= ELF::SHF_GROUP;
@@ -502,7 +504,7 @@ static MCSectionELF *selectELFSectionForGlobal(
502504
503505MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal (
504506 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
505- unsigned Flags = getELFSectionFlags (Kind);
507+ unsigned Flags = getELFSectionFlags (Kind, getTargetTriple () );
506508
507509 // If we have -ffunction-section or -fdata-section then we should emit the
508510 // global value to a uniqued section specifically for it.
0 commit comments