diff --git a/lld/MachO/ConcatOutputSection.h b/lld/MachO/ConcatOutputSection.h --- a/lld/MachO/ConcatOutputSection.h +++ b/lld/MachO/ConcatOutputSection.h @@ -51,7 +51,7 @@ } private: - void mergeFlags(InputSection *input); + void finalizeFlags(InputSection *input); size_t size = 0; uint64_t fileSize = 0; diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp --- a/lld/MachO/ConcatOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -31,7 +31,7 @@ flags = input->flags; } else { align = std::max(align, input->align); - mergeFlags(input); + finalizeFlags(input); } inputs.push_back(input); input->parent = this; @@ -335,28 +335,31 @@ } } -// TODO: this is most likely wrong; reconsider how section flags -// are actually merged. The logic presented here was written without -// any form of informed research. -void ConcatOutputSection::mergeFlags(InputSection *input) { - uint8_t baseType = flags & SECTION_TYPE; - uint8_t inputType = input->flags & SECTION_TYPE; - if (baseType != inputType) - error("Cannot merge section " + input->name + " (type=0x" + - to_hexString(inputType) + ") into " + name + " (type=0x" + - to_hexString(baseType) + "): inconsistent types"); - - constexpr uint32_t strictFlags = S_ATTR_DEBUG | S_ATTR_STRIP_STATIC_SYMS | - S_ATTR_NO_DEAD_STRIP | S_ATTR_LIVE_SUPPORT; - if ((input->flags ^ flags) & strictFlags) - error("Cannot merge section " + input->name + " (flags=0x" + - to_hexString(input->flags) + ") into " + name + " (flags=0x" + - to_hexString(flags) + "): strict flags differ"); +void ConcatOutputSection::finalizeFlags(InputSection *input) { - // Negate pure instruction presence if any section isn't pure. - uint32_t pureMask = ~S_ATTR_PURE_INSTRUCTIONS | (input->flags & flags); + uint8_t inputType = input->flags & SECTION_TYPE; + uint32_t adjusted = S_REGULAR; + switch (inputType) { + default /*type-unspec'ed*/: + // FIXME: Add additional logics here when supporting emitting obj files. + break; + case S_4BYTE_LITERALS: + case S_8BYTE_LITERALS: + case S_16BYTE_LITERALS: + case S_CSTRING_LITERALS: + case S_ZEROFILL: + case S_LAZY_SYMBOL_POINTERS: + case S_MOD_TERM_FUNC_POINTERS: + case S_THREAD_LOCAL_REGULAR: + case S_THREAD_LOCAL_ZEROFILL: + case S_THREAD_LOCAL_VARIABLES: + case S_THREAD_LOCAL_INIT_FUNCTION_POINTERS: + case S_THREAD_LOCAL_VARIABLE_POINTERS: + case S_NON_LAZY_SYMBOL_POINTERS: + case S_SYMBOL_STUBS: + adjusted = input->flags; + break; + } - // Merge the rest - flags |= input->flags; - flags &= pureMask; + flags |= adjusted; } diff --git a/lld/test/MachO/builtin-rename.s b/lld/test/MachO/builtin-rename.s --- a/lld/test/MachO/builtin-rename.s +++ b/lld/test/MachO/builtin-rename.s @@ -5,14 +5,6 @@ # RUN: %t/main.s -o %t/main.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin \ # RUN: %t/renames.s -o %t/renames.o -# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin \ -# RUN: %t/error.s -o %t/error.o - -# RUN: not %lld -o %t/error %t/main.o %t/error.o -lSystem 2>&1 | \ -# RUN: FileCheck %s --check-prefix=ERROR - -## Check the error diagnostic for merging mismatched section types -# ERROR: Cannot merge section __pointers (type=0x0) into __nl_symbol_ptr (type=0x6): inconsistent types ## Check that section and segment renames happen as expected # RUN: %lld -o %t/ydata %t/main.o %t/renames.o -lSystem @@ -151,18 +143,6 @@ __TEXT__StaticInit: .space 8 -#--- error.s - -.section __DATA,__nl_symbol_ptr -.global __DATA__nl_symbol_ptr -__DATA__nl_symbol_ptr: - .space 8 - -.section __IMPORT,__pointers -.global __IMPORT__pointers -__IMPORT__pointers: - .space 8 - #--- main.s .text .global _main