Skip to content

Make kernel not to use boost program_options library #1014

@wkozaczuk

Description

@wkozaczuk

OSv kernel uses following parts of boost libraries:

  • C++ collection and utilities templates mostly used in core/.cc; given corresponding instantiations for each type parameter combination become part of relevant object files, it is not clear how much it contributes to the size of code sections (text) of loader.elf (it seems it should be possible to measure it somehow though bloaty is not capable to show it)
    • boost/algorithm/cxx11/all_of.hpp
    • boost/algorithm/string.hpp
    • boost/algorithm/string/replace.hpp
    • boost/algorithm/string/split.hpp
    • boost/config/warning_disable.hpp
    • boost/date_time.hpp
    • boost/dynamic_bitset.hpp
    • boost/format.hpp
    • boost/intrusive/list.hpp
    • boost/intrusive/parent_from_member.hpp
    • boost/intrusive/set.hpp
    • boost/lockfree/policies.hpp
    • boost/lockfree/queue.hpp
    • boost/lockfree/stack.hpp
    • boost/range/adaptor/reversed.hpp
    • boost/range/algorithm/find.hpp
    • boost/range/algorithm/remove.hpp
    • boost/range/algorithm/transform.hpp
    • boost/spirit/include/qi.hpp
    • boost/utility.hpp
    • boost/variant.hpp
  • libboost_system.a - tiny (10K code and 40K total) library providing error handling
  • libboost_program_options.a - fairly large (400K code and 1.5M total) library to handle command line options and parameters

Unlike boost C++ templates that are used in many places of code and provide critical functionality that would be hard to replace with something hand-written, program options is only used by loader.cc and core/commands.cc and given its substantial size it is desirable to either replace it with something smaller or somehow make use of this library optional. Based on some experiments involving removing programs options completely from kernels it was shown that resulting loader-stripped.elf becomes smaller by 500-600K.

The solution I am proposing is hybrid:

  • rewrite loader.cc::parse_options() by using getopt_long() (which is already part of musl in OSv) instead of boost::program_options
  • extract commands.cc::parse_command_line(const std::string line, bool& ok) and related code as an optional library commands.so that would be used dynamically if found on filesystem; new commands.so would be linked dynamically against libboost_program_options.so; move options parsing code (osv::parse_cmdline()) from commands.cc to new options.cc
  • change loader.cc:prepare_commands() to dynamically use commands.so if present to parse command line or fall back to a simple implementation that handle cmdline as single application

Please note that parse_command_line() is called by loader.cc after VFS is fully setup so nothing prevents us from loading commands.so from filesystem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions