Index: test/tools/llvm-objcopy/ELF/add-section-special.test =================================================================== --- /dev/null +++ test/tools/llvm-objcopy/ELF/add-section-special.test @@ -0,0 +1,15 @@ +# RUN: yaml2obj %s > %t.o +# RUN: llvm-objcopy --add-section=.note.foo=/dev/null %t.o %t-regular-note.o +# RUN: llvm-objcopy --add-section=.note.GNU-stack=/dev/null %t.o %t-gnu-stack.o +# RUN: llvm-readelf --sections %t-regular-note.o | FileCheck %s --check-prefix=NOTE +# RUN: llvm-readelf --sections %t-gnu-stack.o | FileCheck %s --check-prefix=GNU-STACK + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +# NOTE: .note.foo NOTE +# GNU-STACK: .note.GNU-stack PROGBITS Index: tools/llvm-objcopy/ELF/ELFObjcopy.cpp =================================================================== --- tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -508,8 +508,10 @@ auto Buf = std::move(*BufOrErr); auto BufPtr = reinterpret_cast(Buf->getBufferStart()); auto BufSize = Buf->getBufferSize(); - Obj.addSection(SecName, - ArrayRef(BufPtr, BufSize)); + auto &NewSection = Obj.addSection( + SecName, ArrayRef(BufPtr, BufSize)); + if (SecName.startswith(".note") && SecName != ".note.GNU-stack") + NewSection.Type = SHT_NOTE; } }