diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -326,6 +326,9 @@ case 'G': flags |= ELF::SHF_GROUP; break; + case 'R': + flags |= ELF::SHF_GNU_RETAIN; + break; case '?': *UseLastGroup = true; break; diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp --- a/llvm/lib/MC/MCSectionELF.cpp +++ b/llvm/lib/MC/MCSectionELF.cpp @@ -102,6 +102,8 @@ OS << 'T'; if (Flags & ELF::SHF_LINK_ORDER) OS << 'o'; + if (Flags & ELF::SHF_GNU_RETAIN) + OS << 'R'; // If there are target-specific flags, print them. Triple::ArchType Arch = T.getArch(); diff --git a/llvm/test/MC/ELF/section-gnu.s b/llvm/test/MC/ELF/section-gnu.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/ELF/section-gnu.s @@ -0,0 +1,16 @@ +# RUN: llvm-mc -triple=x86_64 %s | FileCheck %s --check-prefix=ASM +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s | llvm-readobj -hS - | FileCheck %s --check-prefix=OBJ + +# ASM: .section retain,"aR",@progbits + +## Note: GNU as sets OSABI to GNU. +# OBJ: OS/ABI: SystemV (0x0) + +# OBJ: Name: retain +# OBJ-NEXT: Type: SHT_PROGBITS +# OBJ-NEXT: Flags [ +# OBJ-NEXT: SHF_ALLOC +# OBJ-NEXT: SHF_GNU_RETAIN +# OBJ-NEXT: ] + +.section retain,"aR",@progbits