aboutsummaryrefslogtreecommitdiff
path: root/src/common/module.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/module.cc')
-rw-r--r--src/common/module.cc30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/common/module.cc b/src/common/module.cc
index c980b96f..0c36516a 100644
--- a/src/common/module.cc
+++ b/src/common/module.cc
@@ -55,6 +55,9 @@ Module::~Module() {
for (vector<StackFrameEntry *>::iterator it = stack_frame_entries_.begin();
it != stack_frame_entries_.end(); it++)
delete *it;
+ for (ExternSet::iterator it = externs_.begin();
+ it != externs_.end(); it++)
+ delete *it;
}
void Module::SetLoadAddress(Address address) {
@@ -64,7 +67,8 @@ void Module::SetLoadAddress(Address address) {
void Module::AddFunction(Function *function) {
std::pair<FunctionSet::iterator,bool> ret = functions_.insert(function);
if (!ret.second) {
- // Free the duplicate we failed to insert because we own it.
+ // Free the duplicate that was not inserted because this Module
+ // now owns it.
delete function;
}
}
@@ -79,11 +83,25 @@ void Module::AddStackFrameEntry(StackFrameEntry *stack_frame_entry) {
stack_frame_entries_.push_back(stack_frame_entry);
}
+void Module::AddExtern(Extern *ext) {
+ std::pair<ExternSet::iterator,bool> ret = externs_.insert(ext);
+ if (!ret.second) {
+ // Free the duplicate that was not inserted because this Module
+ // now owns it.
+ delete ext;
+ }
+}
+
void Module::GetFunctions(vector<Function *> *vec,
vector<Function *>::iterator i) {
vec->insert(i, functions_.begin(), functions_.end());
}
+void Module::GetExterns(vector<Extern *> *vec,
+ vector<Extern *>::iterator i) {
+ vec->insert(i, externs_.begin(), externs_.end());
+}
+
Module::File *Module::FindFile(const string &name) {
// A tricky bit here. The key of each map entry needs to be a
// pointer to the entry's File's name string. This means that we
@@ -211,6 +229,16 @@ bool Module::Write(FILE *stream) {
return ReportError();
}
+ // Write out 'PUBLIC' records.
+ for (ExternSet::const_iterator extern_it = externs_.begin();
+ extern_it != externs_.end(); extern_it++) {
+ Extern *ext = *extern_it;
+ if (0 > fprintf(stream, "PUBLIC %llx 0 %s\n",
+ (unsigned long long) (ext->address - load_address_),
+ ext->name.c_str()))
+ return ReportError();
+ }
+
// Write out 'STACK CFI INIT' and 'STACK CFI' records.
vector<StackFrameEntry *>::const_iterator frame_it;
for (frame_it = stack_frame_entries_.begin();