@@ -1291,28 +1291,32 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
1291
1291
1292
1292
class MyCompilationHandler : public Processor ::CompilationHandler {
1293
1293
public:
1294
- virtual void compiled (const void * code, unsigned size UNUSED, unsigned frameSize UNUSED, const char * class_, const char * name, const char * spec) {
1295
- if (class_ and name and spec) {
1296
- size_t classLen = strlen (class_);
1297
- size_t nameLen = strlen (name);
1298
- size_t specLen = strlen (spec);
1299
-
1300
- char * completeName = (char *)malloc (classLen + nameLen + specLen + 2 );
1301
- sprintf (completeName, " %s.%s%s" , class_, name, spec);
1302
- uint64_t offset = reinterpret_cast <uint64_t >(code) - codeOffset;
1303
- symbols.add (SymbolInfo (offset, completeName));
1304
- // printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec);
1305
- }
1294
+
1295
+ String heapDup (const char * name) {
1296
+ String ret (name);
1297
+ char * n = (char *)heap->allocate (ret.length + 1 );
1298
+ memcpy (n, ret.text , ret.length + 1 );
1299
+ ret.text = n;
1300
+ return ret;
1301
+ }
1302
+
1303
+ virtual void compiled (const void * code, unsigned size UNUSED, unsigned frameSize UNUSED, const char * name) {
1304
+ uint64_t offset = reinterpret_cast <uint64_t >(code) - codeOffset;
1305
+ symbols.add (SymbolInfo (offset, heapDup (name)));
1306
+ // printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec);
1306
1307
}
1307
1308
1308
1309
virtual void dispose () {}
1309
1310
1310
1311
DynamicArray<SymbolInfo> symbols;
1311
1312
uint64_t codeOffset;
1313
+ Heap* heap;
1314
+
1315
+ MyCompilationHandler (uint64_t codeOffset, Heap* heap):
1316
+ codeOffset (codeOffset),
1317
+ heap (heap) {}
1312
1318
1313
- MyCompilationHandler (uint64_t codeOffset):
1314
- codeOffset (codeOffset) {}
1315
- } compilationHandler (reinterpret_cast <uint64_t >(code));
1319
+ } compilationHandler (reinterpret_cast <uint64_t >(code), t->m ->heap );
1316
1320
1317
1321
t->m ->processor ->addCompilationHandler (&compilationHandler);
1318
1322
@@ -1660,13 +1664,13 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
1660
1664
1661
1665
platform->writeObject (bootimageOutput, Slice<SymbolInfo>(bootimageSymbols, 2 ), Slice<const uint8_t >(bootimageData.data , bootimageData.length ), Platform::Writable, TargetBytesPerWord);
1662
1666
1663
- compilationHandler.symbols .add (SymbolInfo (0 , strdup ( " _binary_codeimage_bin_start" ) ));
1664
- compilationHandler.symbols .add (SymbolInfo (image->codeSize , strdup ( " _binary_codeimage_bin_end" ) ));
1667
+ compilationHandler.symbols .add (SymbolInfo (0 , " _binary_codeimage_bin_start" ));
1668
+ compilationHandler.symbols .add (SymbolInfo (image->codeSize , " _binary_codeimage_bin_end" ));
1665
1669
1666
1670
platform->writeObject (codeOutput, Slice<SymbolInfo>(compilationHandler.symbols ), Slice<const uint8_t >(code, image->codeSize ), Platform::Executable, TargetBytesPerWord);
1667
1671
1668
- for (SymbolInfo* sym = compilationHandler.symbols .begin (); sym != compilationHandler.symbols .end (); sym++) {
1669
- free (const_cast <void *>((const void *)sym->name .text ));
1672
+ for (SymbolInfo* sym = compilationHandler.symbols .begin (); sym != compilationHandler.symbols .end () - 2 ; sym++) {
1673
+ t-> m -> heap -> free (const_cast <void *>((const void *)sym->name .text ), sym-> name . length + 1 );
1670
1674
}
1671
1675
}
1672
1676
}
0 commit comments