diff --git a/ci_config.json b/ci_config.json index 2a92454af..522e92e44 100644 --- a/ci_config.json +++ b/ci_config.json @@ -416,6 +416,14 @@ "libpciaccess-dev" ] }, + "libdwarf": { + "_comment": "- provides both dwarfgen and libdwarfp", + "build_options": [ + "libdwarf:dwarfgen=true" + ], + "_comment": "- tests are broken on meson, will make a PR to fix -- @judemille", + "skip_tests": "true" + }, "libffi": { "_comment": "libffi has too many unit tests and it exceed command line limit to rebuild test targets", "test_options": [ diff --git a/releases.json b/releases.json index 6d6bfaa5f..df596665e 100644 --- a/releases.json +++ b/releases.json @@ -1456,6 +1456,19 @@ "2.4.110-1" ] }, + "libdwarf": { + "dependency_names": [ + "libdwarf", + "libdwarfp" + ], + "program_names": [ + "dwarfdump", + "dwarfgen" + ], + "versions": [ + "0.9.1-1" + ] + }, "libebml": { "dependency_names": [ "libebml" diff --git a/subprojects/libdwarf.wrap b/subprojects/libdwarf.wrap new file mode 100644 index 000000000..4b3972368 --- /dev/null +++ b/subprojects/libdwarf.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory = libdwarf-0.9.1 +source_url = https://www.prevanders.net/libdwarf-0.9.1.tar.xz +source_filename = libdwarf-0.9.1.tar.xz +source_hash = 877e81b189edbb075e3e086f6593457d8353d4df09b02e69f3c0c8aa19b51bf4 +patch_directory = libdwarf + +[provide] +dependency_names = libdwarf, libdwarfp +program_names = dwarfdump, dwarfgen diff --git a/subprojects/packagefiles/libdwarf/meson.build b/subprojects/packagefiles/libdwarf/meson.build new file mode 100644 index 000000000..14a07d98a --- /dev/null +++ b/subprojects/packagefiles/libdwarf/meson.build @@ -0,0 +1,270 @@ +project('libdwarf', ['c','cpp'], + version: '0.9.1', + default_options : ['buildtype=debugoptimized', + 'warning_level=3', 'werror=true'], + meson_version : '>=0.54' +) + +# version 0.56 is the first version with project_source_root and +# project_build_root. We use meson.current_source_dir() and +# meson.current_build_dir() (and read these before +# meson knows of other directories) to avoid meson.build_root() +# meson.source_root() and avoid requring 0.56. Ubuntu 20.04, +# for example, uses meson 0.53. + +# meson file system module +fs = import('fs') + +v_arr = meson.project_version().split('.') +v_maj = v_arr[0] +v_min = v_arr[1] +v_mic = v_arr[2] + +lib_type = get_option('default_library') + +# install paths +dir_prefix = get_option('prefix') +dir_include = join_paths(dir_prefix, get_option('includedir')) +dir_pkginclude = join_paths(dir_include, meson.project_name()) +dir_bin = join_paths(dir_prefix, get_option('bindir')) +dir_lib = join_paths(dir_prefix, get_option('libdir')) +dir_data = join_paths(dir_prefix, get_option('datadir')) +dir_pkgdata = join_paths(dir_data, meson.project_name()) +dir_locale = join_paths(dir_prefix, get_option('localedir')) + +# host +windows = import('windows') +host_os = host_machine.system() + +windows = ['windows', 'cygwin'] +#bsd for meson 0.46 and 0.47 +bsd = ['bsd', 'freebsd', 'dragonfly', 'netbsd', 'openbsd'] +linux = ['linux'] +osx = ['darwin'] +sun = ['sunos'] + +sys_linux = linux.contains(host_machine.system()) +sys_bsd = bsd.contains(host_machine.system()) +sys_windows = windows.contains(host_machine.system()) +sys_osx = osx.contains(host_machine.system()) +sys_sun = sun.contains(host_machine.system()) + +# compiler + +cc = meson.get_compiler('c') +cpp = meson.get_compiler('cpp') + +dev_cflags = [] +dev_cppflags = [] +dev_ldflags = [] + +dev_cflags_try = [ + '-Wpointer-arith', + '-Wmissing-declarations', + '-Wstrict-prototypes', + '-Wcomment', + '-Wformat', + '-Wuninitialized', + '-Wshadow', + '-Wno-long-long', + '-Wfloat-compare', + '-Wsign-compare', + '-Wno-missing-field-initializers', + '-fno-omit-frame-pointer' +] +sanitize_flags_try = [ + '-fsanitize=address', + '-fsanitize=leak', + '-fsanitize=undefined' +] + +if sys_windows + if cc.get_id() != 'msvc' + dev_cflags_try += '-Wno-pedantic-ms-format' + endif +else + dev_cflags_try += '-fvisibility=hidden' +endif + +foreach cf: dev_cflags_try + if cc.has_argument(cf) + dev_cflags += cf + endif + if get_option('dwarfgen') == true + if cpp.has_argument(cf) + dev_cppflags += cf + endif + endif +endforeach + +#if fs.isdir('/usr/local/include') +# dev_cflags += '-I/usr/local/include' +#endif +#if fs.isdir('/opt/local/include') +# dev_cflags += '-I/opt/local/include' +#endif + +dwarf_link_args = [] +dev_sanitize = get_option('sanitize') +if dev_sanitize + foreach cf: sanitize_flags_try + if cc.has_argument(cf) + dev_cflags += cf + dwarf_link_args += cf + endif + endforeach +endif + +dev_decompression = get_option('decompression') + +libdwarf_args = [ '-D__USE_MINGW_ANSI_STDIO=0' ] +if cc.get_id() == 'msvc' + libdwarf_args += [ '-D_CRT_NONSTDC_NO_WARNINGS'] +endif + +config_dir = [include_directories('.')] + +# configuration + +# sys/stat.h is for dwarfgen. +header_checks = [ + 'fcntl.h', + 'inttypes.h', + 'malloc.h', + 'stdint.h', + 'sys/stat.h', +] + +if sys_windows == false + header_checks += 'unistd.h' +endif + +config_h = configuration_data() +config_h.set_quoted('PACKAGE_NAME', meson.project_name()) +config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) +config_h.set_quoted('PACKAGE_BIN_DIR', dir_bin) +config_h.set_quoted('PACKAGE_LIB_DIR', dir_lib) +config_h.set_quoted('PACKAGE_DATA_DIR', dir_data) +config_h.set_quoted('LOCALEDIR', dir_locale) + +if host_machine.endian() == 'big' + config_h.set10('WORDS_BIGENDIAN', true) +endif + +if cc.has_function_attribute('unused') == true + config_h.set10('HAVE_UNUSED_ATTRIBUTE', true) +endif + +if cc.has_function('setlocale') == true + if cc.has_function('nl_langinfo') == true + config_h.set10('HAVE_UTF8', true) + endif +endif + +foreach header : header_checks + if cc.has_header(header) + config_h.set10('HAVE_'+header.underscorify().to_upper(), true) + endif +endforeach + +foreach t : [ 'uint64_t', 'uintptr_t', 'intptr_t' ] + if not cc.has_type(t, prefix: '#include ') + error('Sanity check failed: type @0@ not provided via stdint.h'.format(t)) + endif +endforeach + +# Do this early so we have the base source and build directory names +# for this and test/meson.build +project_source_base_root = meson.current_source_dir() +project_build_base_root = meson.current_build_dir() + +subdir('src/lib/libdwarf') +subdir('src/bin/dwarfdump') +have_libdwarfp = false +if get_option('dwarfgen') == true + subdir('src/lib/libdwarfp') + subdir('src/bin/dwarfgen') + have_libdwarfp = true +endif +subdir('src/bin/attr_form') +subdir('src/bin/buildopstab') +subdir('src/bin/builduritable') +subdir('src/bin/gennames') +subdir('src/bin/tag_attr') +subdir('src/bin/tag_tree') +if get_option('dwarfexample') == true + subdir('src/bin/dwarfexample') +endif +subdir('doc') +subdir('test') + +# Use config_h after all subdirs have set values + +#configure_file(output : 'config.h', configuration : config_h) + +# pkg-config files + +pkgconf = configuration_data() + +pkgconf.set('prefix', get_option('prefix')) +pkgconf.set('exec_prefix', '${prefix}') +pkgconf.set('libdir', '${prefix}/@0@'.format(get_option('libdir'))) +pkgconf.set('includedir', '${prefix}/@0@'.format(get_option('includedir'))) +pkgconf.set('pkgincludedir', '${prefix}/@0@'.format(get_option('includedir')) + '/libdwarf') +pkgconf.set('VMAJ', v_maj) +pkgconf.set('PACKAGE_VERSION', meson.project_version()) +if dev_decompression + pkgconf.set('requirements_libdwarf_pc', 'zlib') + pkgconf.set('requirements_libdwarf_pc', 'libzstd') +endif + +pkgconf.set('requirements_libdwarf_libs', '') + +pkg_install_dir = '@0@/pkgconfig'.format(get_option('libdir')) + +configure_file( + input : join_paths(project_source_base_root, 'libdwarf.pc.in'), + output : 'libdwarf.pc', + configuration : pkgconf, + install_dir : pkg_install_dir +) + +# output +# Use config_h after all subdirs have set values + +configure_file(output : 'config.h', configuration : config_h) + +libdwarf_output = ('always') +if dev_decompression + libdwarf_output = 'always (zlib: ' + (zlib_deps.found() ? 'yes' : 'no') + ')' + libdwarf_output += ' always (libzstd: ' + (libzstd_deps.found() ? 'yes' : 'no') + ')' +endif + +libdwarfp_output = (have_libdwarfp ? 'yes' : 'no') + +summary({'OS': host_os, + 'BuildOS-BigEndian': host_machine.endian() == 'big' ? 'yes' : 'no', + 'libdwarf': libdwarf_output, + 'dwarfdump': 'always', + 'libdwarfp': libdwarfp_output, + 'dwarfgen': have_libdwarfp ? 'yes' : 'no', + 'dwarfexample': get_option('dwarfexample') ? 'yes' : 'no', + 'documentation': have_doc, + }, section: 'Configuration Options Summary:') + +summary({'zlib': (zlib_deps.found() ? 'yes' : 'no'), + 'libzstd': (libzstd_deps.found() ? 'yes' : 'no'), + }, section: 'Referenced Libraries:') + +summary({'prefix': dir_prefix, + 'bindir': dir_bin, + 'libdir': dir_lib, + 'incdir': dir_include, + 'pkgincdir': dir_pkginclude, + 'datadir': dir_data, + 'pkgdatadir': dir_pkgdata, + }, section: 'Directories:') + +summary({'compilation': 'ninja', + 'installation': 'ninja install', + }, section: 'Compilation') diff --git a/subprojects/packagefiles/libdwarf/src/bin/dwarfdump/meson.build b/subprojects/packagefiles/libdwarf/src/bin/dwarfdump/meson.build new file mode 100644 index 000000000..e393ef252 --- /dev/null +++ b/subprojects/packagefiles/libdwarf/src/bin/dwarfdump/meson.build @@ -0,0 +1,75 @@ + +dwarfdump_src = [ + 'dd_addrmap.c', + 'dd_attr_form.c', + 'dd_canonical_append.c', + 'dd_checkutil.c', + 'dd_command_options.c', + 'dd_common.c', + 'dd_compiler_info.c', + 'dd_regex.c', + 'dd_safe_strcpy.c', + 'dwarfdump.c', + 'dd_tsearchbal.c', + 'dd_dwconf.c', + 'dd_getopt.c', + 'dd_esb.c', + 'dd_glflags.c', + 'dd_helpertree.c', + 'dd_macrocheck.c', + 'dd_makename.c', + 'dd_naming.c', + 'dd_opscounttab.c', + 'print_abbrevs.c', + 'print_aranges.c', + 'print_debugfission.c', + 'print_die.c', + 'print_debug_addr.c', + 'print_debug_gnu.c', + 'print_debug_names.c', + 'print_debug_sup.c', + 'print_frames.c', + 'print_gdbindex.c', + 'print_hipc_lopc_attr.c', + 'print_lines.c', + 'print_llex_codes.c', + 'print_origloclist_codes.c', + 'print_loclists.c', + 'print_loclists_codes.c', + 'print_macinfo.c', + 'print_macro.c', + 'print_pubnames.c', + 'print_ranges.c', + 'print_rnglists.c', + 'print_section_groups.c', + 'print_sections.c', + 'print_str_offsets.c', + 'print_strings.c', + 'print_tag_attributes_usage.c', + 'dd_sanitized.c', + 'dd_strstrnocase.c', + 'dd_true_section_name.c', + 'dd_uri.c', + 'dd_utf8.c' +] + +pkgdwarfdump = join_paths(dir_data, 'dwarfdump') +dwarfdump_args = [ '-DCONFPREFIX=' + pkgdwarfdump ] + +if (lib_type == 'static') + dwarfdump_args += ['-DLIBDWARF_STATIC'] +endif + +dwarfdump_exe = executable('dwarfdump', dwarfdump_src, + c_args : [ dev_cflags, libdwarf_args, dwarfdump_args ], + link_args : dwarf_link_args , + dependencies : libdwarf, + include_directories : config_dir, + install : true +) + +meson.override_find_program('dwarfdump', dwarfdump_exe) + +install_data('dwarfdump.conf', + install_dir : pkgdwarfdump +) diff --git a/subprojects/packagefiles/libdwarf/src/bin/dwarfgen/meson.build b/subprojects/packagefiles/libdwarf/src/bin/dwarfgen/meson.build new file mode 100644 index 000000000..89020c1da --- /dev/null +++ b/subprojects/packagefiles/libdwarf/src/bin/dwarfgen/meson.build @@ -0,0 +1,26 @@ + +dwarfgen_src = [ + 'createirepformfrombinary.cc', + 'createirepfrombinary.cc', + 'dg_getopt.cc', + 'dwarfgen.cc', + 'irepattrtodbg.cc', + 'ireptodbg.cc' +] + +dg_args = [] +if (lib_type == 'static') + dg_args += ['-DLIBDWARF_STATIC'] +endif + +libdwarfp_dir = include_directories('../../lib/libdwarfp') + +dwarfgen_exe = executable('dwarfgen', dwarfgen_src, + cpp_args : [ dev_cppflags, libdwarf_args,dg_args ], + link_args : dwarf_link_args, + dependencies : [ libdwarf, libdwarfp ], + include_directories : [ config_dir, libdwarfp_dir ], + install : true +) + +meson.override_find_program('dwarfgen', dwarfgen_exe) diff --git a/subprojects/packagefiles/libdwarf/src/lib/libdwarf/meson.build b/subprojects/packagefiles/libdwarf/src/lib/libdwarf/meson.build new file mode 100644 index 000000000..6ba530eaa --- /dev/null +++ b/subprojects/packagefiles/libdwarf/src/lib/libdwarf/meson.build @@ -0,0 +1,148 @@ + +libdwarf_header_src = [ 'libdwarf.h', 'dwarf.h' ] + +libdwarf_src = [ + 'dwarf_abbrev.c', + 'dwarf_alloc.c', + 'dwarf_arange.c', + 'dwarf_crc.c', + 'dwarf_crc32.c', + 'dwarf_debugaddr.c', + 'dwarf_debuglink.c', + 'dwarf_die_deliv.c', + 'dwarf_debugnames.c', + 'dwarf_debug_sup.c', + 'dwarf_dsc.c', + 'dwarf_elf_load_headers.c', + 'dwarf_elfread.c', + 'dwarf_elf_rel_detector.c', + 'dwarf_error.c', + 'dwarf_fill_in_attr_form.c', + 'dwarf_find_sigref.c', + 'dwarf_fission_to_cu.c', + 'dwarf_form.c', + 'dwarf_form_class_names.c', + 'dwarf_frame.c', + 'dwarf_frame2.c', + 'dwarf_gdbindex.c', + 'dwarf_generic_init.c', + 'dwarf_global.c', + 'dwarf_gnu_index.c', + 'dwarf_groups.c', + 'dwarf_harmless.c', + 'dwarf_init_finish.c', + 'dwarf_leb.c', + 'dwarf_line.c', + 'dwarf_loc.c', + 'dwarf_locationop_read.c', + 'dwarf_loclists.c', + 'dwarf_machoread.c', + 'dwarf_macro.c', + 'dwarf_macro5.c', + 'dwarf_memcpy_swap.c', + 'dwarf_names.c', + 'dwarf_object_detector.c', + 'dwarf_object_read_common.c', + 'dwarf_peread.c', + 'dwarf_print_lines.c', + 'dwarf_query.c', + 'dwarf_safe_arithmetic.c', + 'dwarf_safe_strcpy.c', + 'dwarf_secname_ck.c', + 'dwarf_setup_sections.c', + 'dwarf_ranges.c', + 'dwarf_rnglists.c', + 'dwarf_str_offsets.c', + 'dwarf_string.c', + 'dwarf_stringsection.c', + 'dwarf_tied.c', + 'dwarf_tsearchhash.c', + 'dwarf_util.c', + 'dwarf_xu_index.c', +] + +if dev_decompression + zlib_deps = dependency('zlib', method: 'pkg-config', required: false) + libzstd_deps = dependency('libzstd', method: 'pkg-config', required: false) + + if not zlib_deps.found() + if fs.is_dir('/opt/local/lib') and fs.is_file('/opt/local/include/zlib.h') + zlib_deps = declare_dependency(link_args: [ '-L/opt/local/lib','-lz' ], + include_directories: ['/opt/local/include']) + endif + endif + + if not libzstd_deps.found() + if fs.is_dir('/opt/local/lib') and fs.is_file('/opt/local/include/zstd.h') + libzstd_deps = declare_dependency(link_args: ['-L/opt/local/lib','-lzstd' ], + include_directories: ['/opt/local/include']) + endif + endif + + if zlib_deps.found() + message(['Have zlib']) + else + if fs.is_dir('/usr/local/lib') and fs.is_file('/usr/local/include/zlib.h') + zlib_deps = declare_dependency(link_args: [ '-L/usr/local/lib','-lz' ], + include_directories: ['/usr/local/include']) + endif + endif + + if libzstd_deps.found() + message(['Have libzstd']) + else + if fs.is_dir('/usr/local/lib') and fs.is_file('/usr/local/include/zstd.h') + libzstd_deps = declare_dependency(link_args: [ '-L/usr/local/lib', + '-lzstd' ], + include_directories: ['/usr/local/include']) + endif + endif + + # Using set10 as false has the wrong effect, does not + # match what compilers expect from #ifdef in C. + if zlib_deps.found() + if libzstd_deps.found() + config_h.set10('HAVE_ZSTD_H',true) + config_h.set10('HAVE_ZSTD',true) + config_h.set10('HAVE_ZLIB_H',true) + config_h.set10('HAVE_ZLIB',true) + else + zlib_deps = dependency('',required: false) + endif + else + if libzstd_deps.found() + libszstd_deps = dependency('',required: false) + endif + endif +else + zlib_deps = dependency('',required: false) + libzstd_deps = dependency('',required: false) +endif + +if (lib_type == 'shared') + compiler_flags = ['-DLIBDWARF_BUILD'] +else + compiler_flags = ['-DLIBDWARF_STATIC'] +endif + +libdwarf_lib = library('dwarf', libdwarf_src, + c_args : [ dev_cflags, libdwarf_args, compiler_flags ], + dependencies : [ zlib_deps, libzstd_deps ], + gnu_symbol_visibility: 'hidden', + include_directories : config_dir, + install : true, + pic : true, + version : meson.project_version() +) + +libdwarf = declare_dependency( + include_directories : [ include_directories('.')], + link_with : libdwarf_lib, + dependencies : [zlib_deps, libzstd_deps] +) + +meson.override_dependency('libdwarf', libdwarf) + +install_headers(libdwarf_header_src, + install_dir : dir_pkginclude + '-' + v_maj +) diff --git a/subprojects/packagefiles/libdwarf/src/lib/libdwarfp/meson.build b/subprojects/packagefiles/libdwarf/src/lib/libdwarfp/meson.build new file mode 100644 index 000000000..33b5340ed --- /dev/null +++ b/subprojects/packagefiles/libdwarf/src/lib/libdwarfp/meson.build @@ -0,0 +1,60 @@ + +libdwarfp_header_src = [ 'libdwarfp.h' ] + +libdwarfp_src = [ + '../libdwarf/dwarf_memcpy_swap.c', + '../libdwarf/dwarf_string.c', + '../libdwarf/dwarf_tsearchhash.c', + 'dwarf_pro_alloc.c', + 'dwarf_pro_arange.c', + 'dwarf_pro_debug_sup.c', + 'dwarf_pro_die.c', + 'dwarf_pro_dnames.c', + 'dwarf_pro_error.c', + 'dwarf_pro_expr.c', + 'dwarf_pro_finish.c', + 'dwarf_pro_forms.c', + 'dwarf_pro_frame.c', + 'dwarf_pro_funcs.c', + 'dwarf_pro_init.c', + 'dwarf_pro_line.c', + 'dwarf_pro_log_extra_flag_strings.c', + 'dwarf_pro_macinfo.c', + 'dwarf_pro_pubnames.c', + 'dwarf_pro_reloc.c', + 'dwarf_pro_reloc_stream.c', + 'dwarf_pro_reloc_symbolic.c', + 'dwarf_pro_section.c', + 'dwarf_pro_types.c', + 'dwarf_pro_vars.c', + 'dwarf_pro_weaks.c' +] + +libdwarf_dir = include_directories('../libdwarf') +if (lib_type == 'shared') + compiler_flags = ['-DLIBDWARF_BUILD'] +else + compiler_flags = ['-DLIBDWARF_STATIC'] +endif + + +libdwarfp_lib = library('dwarfp', libdwarfp_src, + c_args : [ dev_cflags, libdwarf_args, compiler_flags ], + dependencies : [libdwarf ], + gnu_symbol_visibility: 'hidden', + include_directories : [ config_dir, libdwarf_dir ], + install : true, + pic : true, + version : meson.project_version() +) + +libdwarfp = declare_dependency( + include_directories : [ include_directories('.')], + link_with : libdwarfp_lib, +) + +meson.override_dependency('libdwarfp', libdwarfp) + +install_headers(libdwarfp_header_src, + install_dir : dir_pkginclude + '-' + v_maj +)