@@ -1939,24 +1939,21 @@ void WasmBinaryReader::preScan() {
1939
1939
if (sectionCode == BinaryConsts::Section::Custom) {
1940
1940
auto sectionName = getInlineString ();
1941
1941
1942
- // Code annotations require code locations.
1943
- // TODO: For Branch Hinting, we could note which functions require
1944
- // code locations, as an optimization.
1945
1942
if (sectionName == Annotations::BranchHint) {
1943
+ // Code annotations require code locations.
1944
+ // TODO: For Branch Hinting, we could note which functions require
1945
+ // code locations, as an optimization.
1946
1946
needCodeLocations = true ;
1947
- // Do not break, so we keep looking for DWARF.
1948
- }
1949
-
1950
- // DWARF sections contain code offsets.
1951
- if (DWARF && Debug::isDWARFSection (sectionName)) {
1947
+ } else if (DWARF && Debug::isDWARFSection (sectionName)) {
1948
+ // DWARF sections contain code offsets.
1952
1949
needCodeLocations = true ;
1953
1950
foundDWARF = true ;
1954
- break ;
1951
+ } else if (debugInfo &&
1952
+ sectionName == BinaryConsts::CustomSections::Name) {
1953
+ readNames (oldPos, payloadLen);
1955
1954
}
1956
-
1957
- // TODO: We could stop early if we see the Code section and DWARF is
1958
- // disabled, as BranchHint must appear first, but this seems to
1959
- // make practically no difference in practice.
1955
+ // TODO: We could stop early in some cases, if we've seen enough (e.g.
1956
+ // seeing Code implies no BranchHint will appear, due to ordering).
1960
1957
}
1961
1958
pos = oldPos + payloadLen;
1962
1959
}
@@ -1973,14 +1970,6 @@ void WasmBinaryReader::preScan() {
1973
1970
1974
1971
void WasmBinaryReader::read () {
1975
1972
preScan ();
1976
-
1977
- // Skip ahead and read the name section so we know what names to use when we
1978
- // construct module elements.
1979
- // TODO: Combine this pre-scan with the one in preScan().
1980
- if (debugInfo) {
1981
- findAndReadNames ();
1982
- }
1983
-
1984
1973
readHeader ();
1985
1974
sourceMapReader.parse (wasm);
1986
1975
@@ -4942,32 +4931,7 @@ class NameProcessor {
4942
4931
4943
4932
} // anonymous namespace
4944
4933
4945
- void WasmBinaryReader::findAndReadNames () {
4946
- // Find the names section. Skip the magic and version.
4947
- assert (pos == 0 );
4948
- getInt32 ();
4949
- getInt32 ();
4950
- Index payloadLen, sectionPos;
4951
- bool found = false ;
4952
- while (more ()) {
4953
- uint8_t sectionCode = getInt8 ();
4954
- payloadLen = getU32LEB ();
4955
- sectionPos = pos;
4956
- if (sectionCode == BinaryConsts::Section::Custom) {
4957
- auto sectionName = getInlineString ();
4958
- if (sectionName.equals (BinaryConsts::CustomSections::Name)) {
4959
- found = true ;
4960
- break ;
4961
- }
4962
- }
4963
- pos = sectionPos + payloadLen;
4964
- }
4965
- if (!found) {
4966
- // No names section to read.
4967
- pos = 0 ;
4968
- return ;
4969
- }
4970
-
4934
+ void WasmBinaryReader::readNames (size_t sectionPos, size_t payloadLen) {
4971
4935
// Read the names.
4972
4936
uint32_t lastType = 0 ;
4973
4937
while (pos < sectionPos + payloadLen) {
@@ -5092,9 +5056,6 @@ void WasmBinaryReader::findAndReadNames() {
5092
5056
if (pos != sectionPos + payloadLen) {
5093
5057
throwError (" bad names section position change" );
5094
5058
}
5095
-
5096
- // Reset the position; we were just reading ahead.
5097
- pos = 0 ;
5098
5059
}
5099
5060
5100
5061
void WasmBinaryReader::readFeatures (size_t payloadLen) {
0 commit comments