On Thu, Oct 27, 2016 at 3:06 PM, Benoît Canet <
[email protected]> wrote:

> This is required by go runtime initialization.
>

Again, I would have liked a reference to #795 (
https://github.com/cloudius-systems/osv/issues/795).
That issue also includes a much longer explanation of why this patch is
needed.

It's very sad that this patch is needed, because in my opinion (and not
only mine), passing argv to shared library initialization is a stupid idea
and only glibc does it. But I guess we have no choice because glibc does
it, and go insists on using it :-(


>
> Signed-off-by: Benoît Canet <[email protected]>
> ---
>  core/app.cc        |  2 +-
>  core/elf.cc        | 12 ++++++------
>  include/osv/elf.hh |  4 ++--
>  3 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/core/app.cc b/core/app.cc
> index 0bfcedd..ad8018c 100644
> --- a/core/app.cc
> +++ b/core/app.cc
> @@ -279,7 +279,7 @@ void application::main()
>  {
>      __libc_stack_end = __builtin_frame_address(0);
>
> -    elf::get_program()->init_library();
> +    elf::get_program()->init_library(_args.size(), _argv.get());
>      sched::thread::current()->set_name(_command);
>
>      if (_main) {
> diff --git a/core/elf.cc b/core/elf.cc
> index bf2137c..3dddc48 100644
> --- a/core/elf.cc
> +++ b/core/elf.cc
> @@ -928,19 +928,19 @@ std::string object::pathname()
>  }
>
>  // Run the object's static constructors or similar initialization
>

I would have added a reference in this comment to
https://github.com/cloudius-systems/osv/issues/795 to explain
why we have the unexpected argc/argv arguments.


> -void object::run_init_funcs()
> +void object::run_init_funcs(int argc, char** argv)
>  {
>      if (dynamic_exists(DT_INIT)) {
>          auto func = dynamic_ptr<void>(DT_INIT);
>          if (func) {
> -            reinterpret_cast<void(*)()>(func)();
> +            reinterpret_cast<void(*)(int, char**)>(func)(argc, argv);
>          }
>      }
>      if (dynamic_exists(DT_INIT_ARRAY)) {
> -        auto funcs = dynamic_ptr<void (*)()>(DT_INIT_ARRAY);
> +        auto funcs = dynamic_ptr<void(*)(int, char**)>(DT_INIT_ARRAY);
>          auto nr = dynamic_val(DT_INIT_ARRAYSZ) / sizeof(*funcs);
>          for (auto i = 0u; i < nr; ++i) {
> -            funcs[i]();
> +            funcs[i](argc, argv);
>          }
>      }
>  }
> @@ -1200,7 +1200,7 @@ program::get_library(std::string name,
> std::vector<std::string> extra_path, bool
>      return ret;
>  }
>
> -void program::init_library()
> +void program::init_library(int argc, char** argv)
>  {
>      // get the list of weak pointers before iterating on them
>      std::vector<std::weak_ptr<object>> weak_objects =
> @@ -1212,7 +1212,7 @@ void program::init_library()
>      auto size = weak_objects.size();
>      for (int i = size - 1; i >= 0; i--) {
>         if (auto obj = weak_objects[i].lock()) {
> -            obj->run_init_funcs();
> +            obj->run_init_funcs(argc, argv);
>          }
>      }
>      for (unsigned i = 0; i < size; i++) {
> diff --git a/include/osv/elf.hh b/include/osv/elf.hh
> index d26b22c..90eb8a9 100644
> --- a/include/osv/elf.hh
> +++ b/include/osv/elf.hh
> @@ -335,7 +335,7 @@ public:
>      const std::vector<Elf64_Phdr> *phdrs();
>      std::string soname();
>      std::string pathname();
> -    void run_init_funcs();
> +    void run_init_funcs(int argc, char** argv);
>      void run_fini_funcs();
>      template <typename T = void>
>      T* lookup(const char* name);
> @@ -528,7 +528,7 @@ public:
>      std::shared_ptr<elf::object>
>      get_library(std::string lib, std::vector<std::string> extra_path =
> {}, bool no_init = false);
>
> -    void init_library();
> +    void init_library(int argc = 0, char **argv = nullptr);
>

Nobody calls init_library without paramters, so I guess these defaults (0,
nullptr) aren't really useful?


>
>      /**
>       * Set the default search path for get_library().
> --
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google Groups
> "OSv Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to