Skip to content

Commit ec81ecc

Browse files
committed
fix a crash bug where BSS size calculation was attempted on the value of a data item (bytes) instead of the size of that data item (int)
The size of the bss section was increased with the value of the defined symbol rather than the size of that value (number of bytes). This change fixes that.
1 parent 84d734d commit ec81ecc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

esp32_ulp/assemble.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def append_section(self, value, expected_section=None):
150150
if expected_section is not None and s is not expected_section:
151151
raise TypeError('only allowed in %s section' % expected_section)
152152
if s is BSS:
153-
# just increase BSS size by value
154-
self.offsets[s] += value
153+
# just increase BSS size by length of value
154+
self.offsets[s] += len(value)
155155
else:
156156
self.sections[s].append(value)
157157
self.offsets[s] += len(value)

tests/assemble.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
.data
1515
"""
1616

17+
src_bss = """\
18+
.bss
19+
20+
label:
21+
.long 0
22+
"""
23+
1724

1825
def test_parse_line():
1926
a = Assembler()
@@ -52,6 +59,18 @@ def test_assemble():
5259
assert a.offsets[BSS] == 0
5360

5461

62+
def test_assemble_bss():
63+
a = Assembler()
64+
try:
65+
a.assemble(src_bss)
66+
except TypeError:
67+
raised = True
68+
else:
69+
raised = False
70+
assert not raised
71+
assert a.offsets[BSS] == 4 # 1 word * 4B
72+
73+
5574
def test_symbols():
5675
st = SymbolTable({}, {})
5776
for entry in [
@@ -108,4 +127,5 @@ def test_symbols():
108127
test_parse_line()
109128
test_parse()
110129
test_assemble()
130+
test_assemble_bss()
111131
test_symbols()

0 commit comments

Comments
 (0)