@@ -508,10 +508,17 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
508
508
llvm::DenseSet<uint64_t > SeenGlobals;
509
509
llvm::DenseSet<uint64_t > SeenSegments;
510
510
511
+ // If there is symbol info from the export section, this info will supersede
512
+ // it, but not info from a linking section
513
+ if (!HasLinkingSection) {
514
+ Symbols.clear ();
515
+ }
516
+
511
517
while (Ctx.Ptr < Ctx.End ) {
512
518
uint8_t Type = readUint8 (Ctx);
513
519
uint32_t Size = readVaruint32 (Ctx);
514
520
const uint8_t *SubSectionEnd = Ctx.Ptr + Size;
521
+
515
522
switch (Type) {
516
523
case wasm::WASM_NAMES_FUNCTION:
517
524
case wasm::WASM_NAMES_GLOBAL:
@@ -521,6 +528,16 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
521
528
uint32_t Index = readVaruint32 (Ctx);
522
529
StringRef Name = readString (Ctx);
523
530
wasm::NameType nameType = wasm::NameType::FUNCTION;
531
+ wasm::WasmSymbolInfo Info{Name,
532
+ /* Kind */ wasm::WASM_SYMBOL_TYPE_FUNCTION,
533
+ /* Flags */ 0 ,
534
+ /* ImportModule */ std::nullopt,
535
+ /* ImportName */ std::nullopt,
536
+ /* ExportName */ std::nullopt,
537
+ {/* ElementIndex */ Index}};
538
+ const wasm::WasmSignature *Signature = nullptr ;
539
+ const wasm::WasmGlobalType *GlobalType = nullptr ;
540
+ const wasm::WasmTableType *TableType = nullptr ;
524
541
if (Type == wasm::WASM_NAMES_FUNCTION) {
525
542
if (!SeenFunctions.insert (Index).second )
526
543
return make_error<GenericBinaryError>(
@@ -529,26 +546,50 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
529
546
return make_error<GenericBinaryError>(" invalid function name entry" ,
530
547
object_error::parse_failed);
531
548
532
- if (isDefinedFunctionIndex (Index))
533
- getDefinedFunction (Index).DebugName = Name;
549
+ if (isDefinedFunctionIndex (Index)) {
550
+ wasm::WasmFunction &F = getDefinedFunction (Index);
551
+ F.DebugName = Name;
552
+ Signature = &Signatures[F.SigIndex ];
553
+ if (F.ExportName ) {
554
+ Info.ExportName = F.ExportName ;
555
+ Info.Flags |= wasm::WASM_SYMBOL_BINDING_GLOBAL;
556
+ } else {
557
+ Info.Flags |= wasm::WASM_SYMBOL_BINDING_LOCAL;
558
+ }
559
+ } else {
560
+ Info.Flags |= wasm::WASM_SYMBOL_UNDEFINED;
561
+ }
534
562
} else if (Type == wasm::WASM_NAMES_GLOBAL) {
535
- nameType = wasm::NameType::GLOBAL;
536
563
if (!SeenGlobals.insert (Index).second )
537
564
return make_error<GenericBinaryError>(" global named more than once" ,
538
565
object_error::parse_failed);
539
566
if (!isValidGlobalIndex (Index) || Name.empty ())
540
567
return make_error<GenericBinaryError>(" invalid global name entry" ,
541
568
object_error::parse_failed);
569
+ nameType = wasm::NameType::GLOBAL;
570
+ Info.Kind = wasm::WASM_SYMBOL_TYPE_GLOBAL;
571
+ if (isDefinedGlobalIndex (Index)) {
572
+ GlobalType = &getDefinedGlobal (Index).Type ;
573
+ } else {
574
+ Info.Flags |= wasm::WASM_SYMBOL_UNDEFINED;
575
+ }
542
576
} else {
543
- nameType = wasm::NameType::DATA_SEGMENT;
544
577
if (!SeenSegments.insert (Index).second )
545
578
return make_error<GenericBinaryError>(
546
579
" segment named more than once" , object_error::parse_failed);
547
580
if (Index > DataSegments.size ())
548
581
return make_error<GenericBinaryError>(" invalid data segment name entry" ,
549
582
object_error::parse_failed);
583
+ nameType = wasm::NameType::DATA_SEGMENT;
584
+ Info.Kind = wasm::WASM_SYMBOL_TYPE_DATA;
585
+ Info.Flags |= wasm::WASM_SYMBOL_BINDING_LOCAL;
586
+ assert (Index < DataSegments.size ());
587
+ Info.DataRef = wasm::WasmDataReference{
588
+ Index, 0 , DataSegments[Index].Data .Content .size ()};
550
589
}
551
590
DebugNames.push_back (wasm::WasmDebugName{nameType, Index, Name});
591
+ if (!HasLinkingSection)
592
+ Symbols.emplace_back (Info, GlobalType, TableType, Signature);
552
593
}
553
594
break ;
554
595
}
0 commit comments