mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
give thunks symbol names in the bootimage build, use Heap::allocate instead of malloc
This commit is contained in:
parent
4266b0df7f
commit
7c38ea75e4
@ -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) {}
|
||||
|
||||
|
@ -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<uint64_t>(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<uint64_t>(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<SymbolInfo> symbols;
|
||||
uint64_t codeOffset;
|
||||
Heap* heap;
|
||||
|
||||
MyCompilationHandler(uint64_t codeOffset):
|
||||
codeOffset(codeOffset) {}
|
||||
} compilationHandler(reinterpret_cast<uint64_t>(code));
|
||||
MyCompilationHandler(uint64_t codeOffset, Heap* heap):
|
||||
codeOffset(codeOffset),
|
||||
heap(heap) {}
|
||||
|
||||
} compilationHandler(reinterpret_cast<uint64_t>(code), t->m->heap);
|
||||
|
||||
t->m->processor->addCompilationHandler(&compilationHandler);
|
||||
|
||||
@ -1660,13 +1664,13 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
|
||||
|
||||
platform->writeObject(bootimageOutput, Slice<SymbolInfo>(bootimageSymbols, 2), Slice<const uint8_t>(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<SymbolInfo>(compilationHandler.symbols), Slice<const uint8_t>(code, image->codeSize), Platform::Executable, TargetBytesPerWord);
|
||||
|
||||
for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end(); sym++) {
|
||||
free(const_cast<void*>((const void*)sym->name.text));
|
||||
for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end() - 2; sym++) {
|
||||
t->m->heap->free(const_cast<void*>((const void*)sym->name.text), sym->name.length + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<MyProcessor*>(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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user