.. Copyright (C) 2015-2026 Free Software Foundation, Inc.
   Originally contributed by David Malcolm <dmalcolm@redhat.com>

   This is free software: you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see
   <https://www.gnu.org/licenses/>.

.. default-domain:: c

ABI and API compatibility
=========================

The libgdiagnostics developers strive for ABI and API backward-compatibility:
programs built against libgdiagnostics.so stand a good chance of running
without recompilation against newer versions of libgdiagnostics.so, and
ought to recompile without modification against newer versions of
libgdiagnostics.h.

.. note:: The libgdiagnostics++.h C++ API is more experimental, and less
          locked-down at this time.

API compatibility is achieved by extending the API rather than changing
it.  For ABI compatiblity, we avoid bumping the SONAME, and instead use
symbol versioning to tag each symbol, so that a binary linked against
libgdiagnostics.so is tagged according to the symbols that it uses.

For example, :func:`diagnostic_logical_location_get_kind` was added in
``LIBGDIAGNOSTICS_ABI_1``.  If a client program uses it, this can be detected
from metadata by using ``objdump``:

.. code-block:: bash

   $ objdump -p testsuite/libgdiagnostics/test-logical-location.c.exe | tail -n 7

   Version References:
     required from libc.so.6:
       0x09691a75 0x00 04 GLIBC_2.2.5
     required from libgdiagnostics.so.0:
       0x0ec567d1 0x00 03 LIBGDIAGNOSTICS_ABI_1
       0x0ec567d0 0x00 02 LIBGDIAGNOSTICS_ABI_0

You can see the symbol tags provided by libgdiagnostics.so using ``objdump``:

.. code-block:: bash

   $ objdump -p libgdiagnostics.so | less
   [...snip...]
   Version definitions:
   1 0x01 0x099ea4b0 libgdiagnostics.so.0
   2 0x00 0x0ec567d0 LIBGDIAGNOSTICS_ABI_0
   3 0x00 0x0ec567d1 LIBGDIAGNOSTICS_ABI_1
           LIBGDIAGNOSTICS_ABI_0
   [...snip...]

ABI symbol tags
***************

.. _LIBGDIAGNOSTICS_ABI_0:

``LIBGDIAGNOSTICS_ABI_0``
-------------------------

All entrypoints in the initial release of libgdiagnostics (in GCC 15) are
tagged with ``LIBGDIAGNOSTICS_ABI_0``; these entrypoints are:

  * :func:`diagnostic_manager_new`

  * :func:`diagnostic_manager_release`

  * :func:`diagnostic_manager_set_tool_name`

  * :func:`diagnostic_manager_set_full_name`

  * :func:`diagnostic_manager_set_version_string`

  * :func:`diagnostic_manager_set_version_url`

  * :func:`diagnostic_manager_add_text_sink`

  * :func:`diagnostic_text_sink_set_source_printing_enabled`

  * :func:`diagnostic_text_sink_set_colorize`

  * :func:`diagnostic_text_sink_set_labelled_source_colorization_enabled`

  * :func:`diagnostic_manager_add_sarif_sink`

  * :func:`diagnostic_manager_write_patch`

  * :func:`diagnostic_manager_new_file`

  * :func:`diagnostic_file_set_buffered_content`

  * :func:`diagnostic_manager_debug_dump_file`

  * :func:`diagnostic_manager_new_location_from_file_and_line`

  * :func:`diagnostic_manager_new_location_from_file_line_column`

  * :func:`diagnostic_manager_new_location_from_range`

  * :func:`diagnostic_manager_debug_dump_location`

  * :func:`diagnostic_manager_new_logical_location`

  * :func:`diagnostic_manager_debug_dump_logical_location`

  * :func:`diagnostic_manager_begin_group`

  * :func:`diagnostic_manager_end_group`

  * :func:`diagnostic_begin`

  * :func:`diagnostic_set_cwe`

  * :func:`diagnostic_add_rule`

  * :func:`diagnostic_set_location`

  * :func:`diagnostic_set_location_with_label`

  * :func:`diagnostic_add_location`

  * :func:`diagnostic_add_location_with_label`

  * :func:`diagnostic_set_logical_location`

  * :func:`diagnostic_add_fix_it_hint_insert_before`

  * :func:`diagnostic_add_fix_it_hint_insert_after`

  * :func:`diagnostic_add_fix_it_hint_replace`

  * :func:`diagnostic_add_fix_it_hint_delete`

  * :func:`diagnostic_add_execution_path`

  * :func:`diagnostic_manager_new_execution_path`

  * :func:`diagnostic_take_execution_path`

  * :func:`diagnostic_execution_path_release`

  * :func:`diagnostic_execution_path_add_event`

  * :func:`diagnostic_execution_path_add_event_va`

  * :func:`diagnostic_finish`

  * :func:`diagnostic_finish_va`

  * :func:`diagnostic_physical_location_get_file`

.. _LIBGDIAGNOSTICS_ABI_1:

``LIBGDIAGNOSTICS_ABI_1``
-------------------------
``LIBGDIAGNOSTICS_ABI_1`` covers the addition of these functions for
acccessing values within a :type:`diagnostic_logical_location`:

  * :func:`diagnostic_logical_location_get_kind`

  * :func:`diagnostic_logical_location_get_parent`

  * :func:`diagnostic_logical_location_get_short_name`

  * :func:`diagnostic_logical_location_get_fully_qualified_name`

  * :func:`diagnostic_logical_location_get_decorated_name`

.. _LIBGDIAGNOSTICS_ABI_2:

``LIBGDIAGNOSTICS_ABI_2``
-------------------------
``LIBGDIAGNOSTICS_ABI_2`` covers the addition of these functions for
supporting command-line options and SARIF playback:

  * :func:`diagnostic_manager_add_sink_from_spec`

  * :func:`diagnostic_manager_set_analysis_target`

.. _LIBGDIAGNOSTICS_ABI_3:

``LIBGDIAGNOSTICS_ABI_3``
-------------------------

``LIBGDIAGNOSTICS_ABI_3`` covers the addition of these functions for
working with directed graphs:

  * :func:`diagnostic_manager_new_graph`

  * :func:`diagnostic_manager_take_global_graph`

  * :func:`diagnostic_take_graph`

  * :func:`diagnostic_graph_release`

  * :func:`diagnostic_graph_set_description`

  * :func:`diagnostic_graph_add_node`

  * :func:`diagnostic_graph_add_edge`

  * :func:`diagnostic_graph_get_node_by_id`

  * :func:`diagnostic_graph_get_edge_by_id`

  * :func:`diagnostic_node_set_label`

  * :func:`diagnostic_node_set_location`

  * :func:`diagnostic_node_set_logical_location`

.. _LIBGDIAGNOSTICS_ABI_4:

``LIBGDIAGNOSTICS_ABI_4``
-------------------------

``LIBGDIAGNOSTICS_ABI_4`` covers the addition of these functions for
working with :type:`diagnostic_message_buffer`.

  * :func:`diagnostic_message_buffer_new`

  * :func:`diagnostic_message_buffer_release`

  * :func:`diagnostic_message_buffer_append_str`

  * :func:`diagnostic_message_buffer_append_text`

  * :func:`diagnostic_message_buffer_append_byte`

  * :func:`diagnostic_message_buffer_append_printf`

  * :func:`diagnostic_message_buffer_append_event_id`

  * :func:`diagnostic_message_buffer_begin_url`

  * :func:`diagnostic_message_buffer_end_url`

  * :func:`diagnostic_message_buffer_begin_quote`

  * :func:`diagnostic_message_buffer_end_quote`

  * :func:`diagnostic_message_buffer_begin_color`

  * :func:`diagnostic_message_buffer_end_color`

  * :func:`diagnostic_message_buffer_dump`

  * :func:`diagnostic_finish_via_msg_buf`

  * :func:`diagnostic_add_location_with_label_via_msg_buf`

  * :func:`diagnostic_execution_path_add_event_via_msg_buf`

.. _LIBGDIAGNOSTICS_ABI_5:

``LIBGDIAGNOSTICS_ABI_5``
-------------------------

``LIBGDIAGNOSTICS_ABI_5`` covers the addition of this function:

  * :func:`diagnostic_manager_set_debug_physical_locations`
