From 7c38ea75e4baf777ef5ab207e7f26e8e57e90cf3 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Mon, 7 May 2012 10:00:59 -0600 Subject: [PATCH] give thunks symbol names in the bootimage build, use Heap::allocate instead of malloc --- src/binaryToObject/tools.h | 2 +- src/bootimage.cpp | 42 +++++++++++++++++++++----------------- src/compile.cpp | 22 +++++++++++++++++++- src/processor.h | 2 +- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/binaryToObject/tools.h b/src/binaryToObject/tools.h index 999d010535..ad7e81f86f 100644 --- a/src/binaryToObject/tools.h +++ b/src/binaryToObject/tools.h @@ -55,7 +55,7 @@ public: unsigned addr; String name; - inline SymbolInfo(uint64_t addr, const char* name): + inline SymbolInfo(uint64_t addr, const String& name): addr(addr), name(name) {} diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 72b41028a2..27f0e2aa8a 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -1291,28 +1291,32 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp class MyCompilationHandler : public Processor::CompilationHandler { public: - virtual void compiled(const void* code, unsigned size UNUSED, unsigned frameSize UNUSED, const char* class_, const char* name, const char* spec) { - if (class_ and name and spec) { - size_t classLen = strlen(class_); - size_t nameLen = strlen(name); - size_t specLen = strlen(spec); - - char* completeName = (char*)malloc(classLen + nameLen + specLen + 2); - sprintf(completeName, "%s.%s%s", class_, name, spec); - uint64_t offset = reinterpret_cast(code) - codeOffset; - symbols.add(SymbolInfo(offset, completeName)); - // printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec); - } + + String heapDup(const char* name) { + String ret(name); + char* n = (char*)heap->allocate(ret.length + 1); + memcpy(n, ret.text, ret.length + 1); + ret.text = n; + return ret; + } + + virtual void compiled(const void* code, unsigned size UNUSED, unsigned frameSize UNUSED, const char* name) { + uint64_t offset = reinterpret_cast(code) - codeOffset; + symbols.add(SymbolInfo(offset, heapDup(name))); + // printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec); } virtual void dispose() {} DynamicArray symbols; uint64_t codeOffset; + Heap* heap; - MyCompilationHandler(uint64_t codeOffset): - codeOffset(codeOffset) {} - } compilationHandler(reinterpret_cast(code)); + MyCompilationHandler(uint64_t codeOffset, Heap* heap): + codeOffset(codeOffset), + heap(heap) {} + + } compilationHandler(reinterpret_cast(code), t->m->heap); t->m->processor->addCompilationHandler(&compilationHandler); @@ -1660,13 +1664,13 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp platform->writeObject(bootimageOutput, Slice(bootimageSymbols, 2), Slice(bootimageData.data, bootimageData.length), Platform::Writable, TargetBytesPerWord); - compilationHandler.symbols.add(SymbolInfo(0, strdup("_binary_codeimage_bin_start"))); - compilationHandler.symbols.add(SymbolInfo(image->codeSize, strdup("_binary_codeimage_bin_end"))); + compilationHandler.symbols.add(SymbolInfo(0, "_binary_codeimage_bin_start")); + compilationHandler.symbols.add(SymbolInfo(image->codeSize, "_binary_codeimage_bin_end")); platform->writeObject(codeOutput, Slice(compilationHandler.symbols), Slice(code, image->codeSize), Platform::Executable, TargetBytesPerWord); - for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end(); sym++) { - free(const_cast((const void*)sym->name.text)); + for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end() - 2; sym++) { + t->m->heap->free(const_cast((const void*)sym->name.text), sym->name.length + 1); } } } diff --git a/src/compile.cpp b/src/compile.cpp index 395e7a3114..1adce59df7 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -9087,6 +9087,20 @@ class MyProcessor: public Processor { CompilationHandlerList* compilationHandlers; }; +const char* +stringOrNull(const char* str) { + if(str) { + return str; + } else { + return "(null)"; + } +} + +size_t +stringOrNullSize(const char* str) { + return strlen(stringOrNull(str)); +} + void logCompile(MyThread* t, const void* code, unsigned size, const char* class_, const char* name, const char* spec) @@ -9108,9 +9122,15 @@ logCompile(MyThread* t, const void* code, unsigned size, const char* class_, class_, name, spec); } + size_t nameLength = stringOrNullSize(class_) + stringOrNullSize(name) + stringOrNullSize(spec) + 2; + + THREAD_RUNTIME_ARRAY(t, char, completeName, nameLength); + + sprintf(RUNTIME_ARRAY_BODY(completeName), "%s.%s%s", stringOrNull(class_), stringOrNull(name), stringOrNull(spec)); + MyProcessor* p = static_cast(t->m->processor); for(CompilationHandlerList* h = p->compilationHandlers; h; h = h->next) { - h->handler->compiled(code, 0, 0, class_, name, spec); + h->handler->compiled(code, 0, 0, RUNTIME_ARRAY_BODY(completeName)); } } diff --git a/src/processor.h b/src/processor.h index 3794570b14..a6b548387f 100644 --- a/src/processor.h +++ b/src/processor.h @@ -43,7 +43,7 @@ class Processor { class CompilationHandler { public: - virtual void compiled(const void* code, unsigned size, unsigned frameSize, const char* class_, const char* name, const char* spec) = 0; + virtual void compiled(const void* code, unsigned size, unsigned frameSize, const char* name) = 0; virtual void dispose() = 0; };