Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/11610
Change subject: systemc: Get sc_main to work even when dynamically linked.
......................................................................
systemc: Get sc_main to work even when dynamically linked.
Unfortunately multiply defined weak symbols don't work like they're
supposed to when the different versions are across dynamic linking
boundaries.
Fortunately, a weak symbol with no definition at all will still
consistently evaluate as 0, and a singularly defined weak symbol will
still resolve correctly.
Instead of relying on a weak version of sc_main being overridden by a
strong/non-default definition, this change leaves it as undefined and
detects at run time whether the symbol resolves to 0 or to an actual
code location.
Change-Id: I31c4ff769b0c52277c6cf4845ca3f85000009583
---
M src/systemc/core/sc_main.cc
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/systemc/core/sc_main.cc b/src/systemc/core/sc_main.cc
index 2ca5ed4..fec3fae 100644
--- a/src/systemc/core/sc_main.cc
+++ b/src/systemc/core/sc_main.cc
@@ -38,16 +38,8 @@
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/utils/sc_report_handler.hh"
-// A default version of this function in case one isn't otherwise defined.
-// This ensures everything will link properly whether or not the user
defined
-// a custom sc_main function. If they didn't but still try to call it,
throw
-// an error and die.
-[[gnu::weak]] int
-sc_main(int argc, char *argv[])
-{
- // If python attempts to call sc_main but no sc_main was defined...
- fatal("sc_main called but not defined.\n");
-}
+// A weak symbol to detect if sc_main has been defined, and if so where it
is.
+[[gnu::weak]] int sc_main(int argc, char *argv[]);
namespace sc_core
{
@@ -65,7 +57,12 @@
void
main()
{
- ::sc_main(_argc, _argv);
+ if (::sc_main) {
+ ::sc_main(_argc, _argv);
+ } else {
+ // If python tries to call sc_main but no sc_main was
defined...
+ fatal("sc_main called but not defined.\n");
+ }
}
};
--
To view, visit https://gem5-review.googlesource.com/11610
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I31c4ff769b0c52277c6cf4845ca3f85000009583
Gerrit-Change-Number: 11610
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev