Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitizer build #33

Merged
merged 11 commits into from
Jun 11, 2020
Merged

Sanitizer build #33

merged 11 commits into from
Jun 11, 2020

Conversation

jmgorius
Copy link
Collaborator

Add support for sanitizer builds and update the CI configuration accordingly. Simplify the CI configuration slightly by centralizing configuration options in the top-level environment and by using multi-line run commands.

@jmgorius
Copy link
Collaborator Author

There seems to be undefined references to sanitizer functions. I will try to figure out why this happens.

@jmgorius
Copy link
Collaborator Author

jmgorius commented Jun 11, 2020

The build is now fixed. The sanitizers have detected a memory leak in the simulator.
The leak probably comes from

State *init_state() {
  auto state = new State();
  auto zeroSlot = Slot(Time());
  state->queue.push(zeroSlot);
  return state;
}

in lib/Simulator/signals-runtime-wrappers.cpp. The State instance is never deleted.

@jmgorius
Copy link
Collaborator Author

After some more investigation, it turns out the memory is lost in the call to engine->invoke here

int Engine::simulate(int n) {
  assert(engine && "engine not found");
  assert(state && "state not found");

  SmallVector<void *, 1> arg({&state});
  // initialize simulation state
  auto invocationResult = engine->invoke("llhd_init", arg);
  if (invocationResult) {
    llvm::errs() << "Failed invocation of llhd_init: " << invocationResult;
    return -1;
  }
  // ...
}

@rodonisi
Copy link
Collaborator

Thanks a lot for the PR and looking into it, that's awesome!
That specific ExecutionEngine invocation includes malloc'ing memory regions for the signal's values. Those pointers are then stored in the State struct but never free'd explicitly. What would you suggest to be a good way to handle this? Do you think having a State destructor that loops over signals and explicitly calls free for each of them would be fine?

@jmgorius
Copy link
Collaborator Author

Yes, I think it would be a good solution. Right now the leaks are small but I would expect real-world examples to have way more allocations, so taking care of it would not hurt.

If you want to stay C-friendly you could also have a free_state(State *state) function that takes care of the deallocation.

* note: any signal with index higher than `nSigs` is a subsignal and points inside a region of another pointer
@rodonisi
Copy link
Collaborator

It works now!
I don't think there's a need for a C-friendly function for the deallocation, as the state lives and is mainly interacted with in simulator itself

@jmgorius
Copy link
Collaborator Author

I don't think there's a need for a C-friendly function for the deallocation, as the state lives and is mainly interacted with in simulator itself

True. Nice to see that this was the only detected issue!

@rodonisi
Copy link
Collaborator

Otherwise there's just a missing newline in the new cmake module, I'm not sure how important that is though

@jmgorius
Copy link
Collaborator Author

Fixed it.

@rodonisi
Copy link
Collaborator

Allright, thanks a lot :)

@rodonisi rodonisi merged commit 23716f1 into master Jun 11, 2020
@rodonisi rodonisi deleted the sanitizer-build branch June 11, 2020 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants