@@ -582,11 +582,10 @@ Symbol *SymbolTable::addDefinedTable(StringRef name, uint32_t flags,
582582// With LTO these attributes are not available when the bitcode is read and only
583583// become available when the LTO object is read. In this case we silently
584584// replace the empty attributes with the valid ones.
585- template <typename T>
586- static void setImportAttributes (T *existing,
587- std::optional<StringRef> importName,
588- std::optional<StringRef> importModule,
589- uint32_t flags, InputFile *file) {
585+ static void
586+ updateExistingUndefined (Symbol *existing, uint32_t flags, InputFile *file,
587+ std::optional<StringRef> importName = {},
588+ std::optional<StringRef> importModule = {}) {
590589 if (importName) {
591590 if (!existing->importName )
592591 existing->importName = importName;
@@ -612,6 +611,10 @@ static void setImportAttributes(T *existing,
612611 if (existing->isWeak () && binding != WASM_SYMBOL_BINDING_WEAK) {
613612 existing->flags = (existing->flags & ~WASM_SYMBOL_BINDING_MASK) | binding;
614613 }
614+
615+ // Certain flags such as NO_STRIP should be maintianed if either old or
616+ // new symbol is marked as such.
617+ existing->flags |= flags & WASM_SYMBOL_NO_STRIP;
615618}
616619
617620Symbol *SymbolTable::addUndefinedFunction (StringRef name,
@@ -675,12 +678,10 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name,
675678 replaceSym ();
676679 }
677680 if (existingUndefined) {
678- setImportAttributes (existingUndefined, importName, importModule, flags ,
679- file );
681+ updateExistingUndefined (existingUndefined, flags, file, importName ,
682+ importModule );
680683 if (isCalledDirectly)
681684 existingUndefined->isCalledDirectly = true ;
682- if (s->isWeak ())
683- s->flags = flags;
684685 }
685686 }
686687
@@ -707,8 +708,8 @@ Symbol *SymbolTable::addUndefinedData(StringRef name, uint32_t flags,
707708 lazy->extract ();
708709 } else if (s->isDefined ()) {
709710 checkDataType (s, file);
710- } else if (s-> isWeak ()) {
711- s-> flags = flags;
711+ } else {
712+ updateExistingUndefined (s, flags, file) ;
712713 }
713714 return s;
714715}
@@ -734,8 +735,8 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef name,
734735 lazy->extract ();
735736 else if (s->isDefined ())
736737 checkGlobalType (s, file, type);
737- else if (s-> isWeak ())
738- s-> flags = flags;
738+ else
739+ updateExistingUndefined (s, flags, file) ;
739740 return s;
740741}
741742
@@ -760,8 +761,8 @@ Symbol *SymbolTable::addUndefinedTable(StringRef name,
760761 lazy->extract ();
761762 else if (s->isDefined ())
762763 checkTableType (s, file, type);
763- else if (s-> isWeak ())
764- s-> flags = flags;
764+ else
765+ updateExistingUndefined (s, flags, file) ;
765766 return s;
766767}
767768
@@ -786,12 +787,13 @@ Symbol *SymbolTable::addUndefinedTag(StringRef name,
786787 lazy->extract ();
787788 else if (s->isDefined ())
788789 checkTagType (s, file, sig);
789- else if (s-> isWeak ())
790- s-> flags = flags;
790+ else
791+ updateExistingUndefined (s, flags, file) ;
791792 return s;
792793}
793794
794795TableSymbol *SymbolTable::createUndefinedIndirectFunctionTable (StringRef name) {
796+ LLVM_DEBUG (llvm::dbgs () << " createUndefinedIndirectFunctionTable\n " );
795797 WasmLimits limits{0 , 0 , 0 , 0 }; // Set by the writer.
796798 WasmTableType *type = make<WasmTableType>();
797799 type->ElemType = ValType::FUNCREF;
@@ -806,6 +808,7 @@ TableSymbol *SymbolTable::createUndefinedIndirectFunctionTable(StringRef name) {
806808}
807809
808810TableSymbol *SymbolTable::createDefinedIndirectFunctionTable (StringRef name) {
811+ LLVM_DEBUG (llvm::dbgs () << " createDefinedIndirectFunctionTable\n " );
809812 const uint32_t invalidIndex = -1 ;
810813 WasmLimits limits{0 , 0 , 0 , 0 }; // Set by the writer.
811814 WasmTableType type{ValType::FUNCREF, limits};
0 commit comments