Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
COMMON_FLAGS="-nostdlib"
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Wed May 31, 2023 9:26 am    Post subject: COMMON_FLAGS="-nostdlib" Reply with quote

I have tried to build a patched version of atk with -nostdlib.
Code:
COMMON_FLAGS="-O2 -pipe -march=native -flto=4 -nostdlib"

However, when I do that I get:
Code:
../atk-2.38.0/meson.build:1:0: ERROR: Executables created by c compiler x86_64-pc-linux-gnu-gcc are not runnable.

Any ideas how to fix this?
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Wed May 31, 2023 2:22 pm    Post subject: Re: COMMON_FLAGS="-nostdlib" Reply with quote

stefan11111 wrote:
Code:
../atk-2.38.0/meson.build:1:0: ERROR: Executables created by c compiler x86_64-pc-linux-gnu-gcc are not runnable.

That's expected. Option -nostdlib prevents linking by default to the libc, and to the system startup files (*crt*.o) and helper libraries like libgcc. Making the resulting executables essentially unusable on what the C and C++ standards call a "hosted environment".

What did you think that you needed -nostdlib for?
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Wed May 31, 2023 8:13 pm    Post subject: Re: COMMON_FLAGS="-nostdlib" Reply with quote

GDH-gentoo wrote:
stefan11111 wrote:
Code:
../atk-2.38.0/meson.build:1:0: ERROR: Executables created by c compiler x86_64-pc-linux-gnu-gcc are not runnable.

That's expected. Option -nostdlib prevents linking by default to the libc, and to the system startup files (*crt*.o) and helper libraries like libgcc. Making the resulting executables essentially unusable on what the C and C++ standards call a "hosted environment".

What did you think that you needed -nostdlib for?

The patch I linked strips atk to a couple of functions and typedefs. I don't want to link this against libc if I don't have too.
I've had success in the past with such approaches.
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Wed May 31, 2023 9:38 pm    Post subject: Reply with quote

stefan11111 wrote:
I've had success in the past with such approaches.

It won't work if the build system tries to compile and run an executable with your supplied CFLAGS, as ATK's seemingly does. It works for your fake-libudev because its build system is just a makefile that doesn't try to run anything, it only builds a shared library that has no unresolved symbols.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 991
Location: Richmond Hill, Canada

PostPosted: Thu Jun 01, 2023 12:24 am    Post subject: Reply with quote

stefan11111,

You may want to read about Hosted versus non-hosted (standalone) to understand what does it mean when using -nostdlib.
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Wed Jun 07, 2023 10:14 am    Post subject: Reply with quote

I fixed the problem by replacing the meson build system with a Makefile. Seems nothing can beat that.
I changed the repo to this.

A comparison:
Code:
$ ls -lah /usr/lib64/libatk-1.0.so*
-rwxr-xr-x 1 root root 46K Jun  7 13:10 /usr/lib64/libatk-1.0.so
lrwxrwxrwx 1 root root  13 Jun  7 13:10 /usr/lib64/libatk-1.0.so.0 -> libatk-1.0.so
-rwxr-xr-x 1 root root 78K May 21 16:54 /usr/lib64/libatk-1.0.so.0.bak


Code:
$ objdump -d /usr/lib64/libatk-1.0.so | wc -l
1887
$ objdump -d /usr/lib64/libatk-1.0.so | wc -l
1887


Code:
$ ldd /usr/lib64/*atk*
/usr/lib64/libatk-1.0.so:
        statically linked
/usr/lib64/libatk-1.0.so.0:
        statically linked
/usr/lib64/libatk-1.0.so.0.bak:
        linux-vdso.so.1 (0x00007ffe2bfbc000)
        libglib-2.0.so.0 => /usr/lib64/libglib-2.0.so.0 (0x00007f93d5579000)
        libgobject-2.0.so.0 => /usr/lib64/libgobject-2.0.so.0 (0x00007f93d5518000)
        libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f93d547c000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f93d52a9000)
        libffi.so.8 => /usr/lib64/libffi.so.8 (0x00007f93d529e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f93d56e0000)


I also added an ebuild for it to my overlay.
When I emerge it, I get a warning I don't get if I emerge fake-libudev.
Code:
 * QA Notice: The following shared libraries lack NEEDED entries
 * /usr/lib64/libatk-1.0.so

Any idea how to fix this?
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Wed Jun 07, 2023 12:53 pm    Post subject: Reply with quote

stefan11111 wrote:
When I emerge it, I get a warning I don't get if I emerge fake-libudev.
Code:
 * QA Notice: The following shared libraries lack NEEDED entries
 * /usr/lib64/libatk-1.0.so

Any idea how to fix this?

That's a Portage QA check, post the output of nm -D /usr/lib64/libatk-1.0.so.0. For your modified libatk, obviously.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Wed Jun 07, 2023 6:49 pm    Post subject: Reply with quote

GDH-gentoo wrote:
stefan11111 wrote:
When I emerge it, I get a warning I don't get if I emerge fake-libudev.
Code:
 * QA Notice: The following shared libraries lack NEEDED entries
 * /usr/lib64/libatk-1.0.so

Any idea how to fix this?

That's a Portage QA check, post the output of nm -D /usr/lib64/libatk-1.0.so.0. For your modified libatk, obviously.

Code:
00000000000061f5 T atk_action_do_action
0000000000006201 T atk_action_get_description
0000000000006213 T atk_action_get_keybinding
000000000000620d T atk_action_get_localized_name
00000000000061fb T atk_action_get_n_actions
0000000000006207 T atk_action_get_name
00000000000061ef T atk_action_get_type
0000000000006219 T atk_action_set_description
00000000000070e8 T atk_add_focus_tracker
00000000000070f0 T atk_add_global_event_listener
00000000000070f7 T atk_add_key_event_listener
00000000000070bb T atk_attribute_set_free
0000000000006225 T atk_component_add_focus_handler
000000000000622c T atk_component_contains
0000000000006247 T atk_component_get_alpha
0000000000006238 T atk_component_get_extents
000000000000623b T atk_component_get_layer
0000000000006241 T atk_component_get_mdi_zorder
0000000000006239 T atk_component_get_position
000000000000623a T atk_component_get_size
000000000000621f T atk_component_get_type
000000000000624c T atk_component_grab_focus
0000000000006232 T atk_component_ref_accessible_at_point
000000000000622b T atk_component_remove_focus_handler
0000000000006264 T atk_component_scroll_to
000000000000626a T atk_component_scroll_to_point
0000000000006252 T atk_component_set_extents
0000000000006258 T atk_component_set_position
000000000000625e T atk_component_set_size
0000000000006300 T atk_coord_type_get_type
000000000000628e T atk_document_get_attributes
0000000000006294 T atk_document_get_attribute_value
00000000000062a0 T atk_document_get_current_page_number
0000000000006282 T atk_document_get_document
000000000000627c T atk_document_get_document_type
0000000000006288 T atk_document_get_locale
00000000000062a6 T atk_document_get_page_count
0000000000006276 T atk_document_get_type
000000000000629a T atk_document_set_attribute_value
00000000000062ba T atk_editable_text_copy_text
00000000000062bb T atk_editable_text_cut_text
00000000000062bc T atk_editable_text_delete_text
00000000000062ac T atk_editable_text_get_type
00000000000062b9 T atk_editable_text_insert_text
00000000000062bd T atk_editable_text_paste_text
00000000000062b2 T atk_editable_text_set_run_attributes
00000000000062b8 T atk_editable_text_set_text_contents
00000000000070e7 T atk_focus_tracker_init
00000000000070ef T atk_focus_tracker_notify
000000000000715f T atk_get_binary_age
0000000000006ddf T atk_get_default_registry
0000000000007104 T atk_get_focus_object
0000000000007165 T atk_get_interface_age
000000000000714d T atk_get_major_version
0000000000007159 T atk_get_micro_version
0000000000007153 T atk_get_minor_version
00000000000070fe T atk_get_root
000000000000710a T atk_get_toolkit_name
0000000000007110 T atk_get_toolkit_version
0000000000007116 T atk_get_version
0000000000006312 T atk_gobject_accessible_for_object
0000000000006318 T atk_gobject_accessible_get_object
000000000000630c T atk_gobject_accessible_get_type
0000000000006330 T atk_hyperlink_get_end_index
0000000000006348 T atk_hyperlink_get_n_anchors
000000000000632a T atk_hyperlink_get_object
0000000000006336 T atk_hyperlink_get_start_index
000000000000631e T atk_hyperlink_get_type
0000000000006324 T atk_hyperlink_get_uri
000000000000635a T atk_hyperlink_impl_get_hyperlink
0000000000006354 T atk_hyperlink_impl_get_type
0000000000006342 T atk_hyperlink_is_inline
000000000000634e T atk_hyperlink_is_selected_link
000000000000633c T atk_hyperlink_is_valid
00000000000062c4 T atk_hyperlink_state_flags_get_type
0000000000006366 T atk_hypertext_get_link
0000000000006372 T atk_hypertext_get_link_index
000000000000636c T atk_hypertext_get_n_links
0000000000006360 T atk_hypertext_get_type
000000000000637e T atk_image_get_image_description
000000000000638c T atk_image_get_image_locale
000000000000638b T atk_image_get_image_position
0000000000006384 T atk_image_get_image_size
0000000000006378 T atk_image_get_type
0000000000006385 T atk_image_set_image_description
0000000000006415 T atk_implementor_get_type
00000000000064dd T atk_implementor_ref_accessible
00000000000062fa T atk_key_event_type_get_type
00000000000062d0 T atk_layer_get_type
0000000000006395 T atk_marshal_VOID__DOUBLE_STRING
0000000000006392 T atk_marshal_VOID__INT_INT
0000000000006394 T atk_marshal_VOID__INT_INT_INT_STRING
0000000000006393 T atk_marshal_VOID__INT_INT_STRING
0000000000006180 T atk_marshal_VOID__STRING_BOOLEAN
000000000000639e T atk_misc_get_instance
0000000000006396 T atk_misc_get_type
000000000000c0b8 B atk_misc_instance
000000000000639c T atk_misc_threads_enter
000000000000639d T atk_misc_threads_leave
00000000000063b0 T atk_no_op_object_factory_get_type
00000000000063b6 T atk_no_op_object_factory_new
00000000000063a4 T atk_no_op_object_get_type
00000000000063aa T atk_no_op_object_new
0000000000006565 T atk_object_add_relationship
00000000000064d5 T atk_object_connect_property_change_handler
0000000000006578 T atk_object_factory_create_accessible
000000000000657f T atk_object_factory_get_accessible_type
0000000000006585 T atk_object_factory_get_type
000000000000657e T atk_object_factory_invalidate
0000000000006571 T atk_object_get_accessible_id
00000000000064e3 T atk_object_get_attributes
0000000000006421 T atk_object_get_description
00000000000064cb T atk_object_get_index_in_parent
00000000000064b9 T atk_object_get_layer
00000000000064bf T atk_object_get_mdi_zorder
000000000000649b T atk_object_get_n_accessible_children
000000000000641b T atk_object_get_name
0000000000006559 T atk_object_get_object_locale
0000000000006427 T atk_object_get_parent
00000000000064b3 T atk_object_get_role
00000000000063bc T atk_object_get_type
00000000000064e9 T atk_object_initialize
00000000000064dc T atk_object_notify_state_change
0000000000006495 T atk_object_peek_parent
00000000000064a1 T atk_object_ref_accessible_child
00000000000064a7 T atk_object_ref_relation_set
00000000000064c5 T atk_object_ref_state_set
00000000000064db T atk_object_remove_property_change_handler
000000000000656b T atk_object_remove_relationship
0000000000006577 T atk_object_set_accessible_id
00000000000064d2 T atk_object_set_description
00000000000064d1 T atk_object_set_name
00000000000064d3 T atk_object_set_parent
00000000000064d4 T atk_object_set_role
0000000000006592 T atk_plug_get_id
000000000000658b T atk_plug_new
0000000000006591 T atk_plug_set_child
00000000000061bb T atk_range_copy
00000000000061c1 T atk_range_free
0000000000006dcc T atk_range_get_description
0000000000006dc2 T atk_range_get_lower_limit
0000000000006d72 T atk_range_get_type
0000000000006dc7 T atk_range_get_upper_limit
0000000000006dbc T atk_range_new
0000000000006270 T atk_rectangle_get_type
0000000000006dd9 T atk_registry_get_factory
0000000000006dd3 T atk_registry_get_factory_type
0000000000006dd2 T atk_registry_set_factory_type
0000000000006e0f T atk_relation_add_target
0000000000006e03 T atk_relation_get_relation_type
0000000000006e09 T atk_relation_get_target
0000000000006de5 T atk_relation_get_type
0000000000006dfd T atk_relation_new
0000000000006e10 T atk_relation_remove_target
0000000000006e29 T atk_relation_set_add
0000000000006e3c T atk_relation_set_add_relation_by_type
0000000000006e22 T atk_relation_set_contains
0000000000006e3d T atk_relation_set_contains_target
0000000000006e2a T atk_relation_set_get_n_relations
0000000000006e30 T atk_relation_set_get_relation
0000000000006e36 T atk_relation_set_get_relation_by_type
0000000000006e16 T atk_relation_set_get_type
0000000000006e1c T atk_relation_set_new
0000000000006e28 T atk_relation_set_remove
0000000000006df7 T atk_relation_type_for_name
0000000000006df1 T atk_relation_type_get_name
00000000000062d6 T atk_relation_type_get_type
0000000000006deb T atk_relation_type_register
00000000000070ee T atk_remove_focus_tracker
00000000000070f6 T atk_remove_global_event_listener
00000000000070fd T atk_remove_key_event_listener
000000000000655f T atk_role_for_name
0000000000006553 T atk_role_get_localized_name
000000000000654d T atk_role_get_name
00000000000062ca T atk_role_get_type
00000000000064ad T atk_role_register
00000000000062be T atk_scroll_type_get_type
0000000000006e49 T atk_selection_add_selection
0000000000006e4f T atk_selection_clear_selection
0000000000006e5b T atk_selection_get_selection_count
0000000000006e43 T atk_selection_get_type
0000000000006e61 T atk_selection_is_child_selected
0000000000006e55 T atk_selection_ref_selection
0000000000006e67 T atk_selection_remove_selection
0000000000006e6d T atk_selection_select_all_selection
0000000000006e79 T atk_socket_embed
0000000000006e7a T atk_socket_is_occupied
0000000000006e73 T atk_socket_new
0000000000006ea4 T atk_state_set_add_state
0000000000006eaa T atk_state_set_add_states
0000000000006ebe T atk_state_set_and_sets
0000000000006eab T atk_state_set_clear_states
0000000000006eac T atk_state_set_contains_state
0000000000006eb2 T atk_state_set_contains_states
0000000000006e92 T atk_state_set_get_type
0000000000006e9e T atk_state_set_is_empty
0000000000006e98 T atk_state_set_new
0000000000006ec4 T atk_state_set_or_sets
0000000000006eb8 T atk_state_set_remove_state
0000000000006eca T atk_state_set_xor_sets
0000000000006e8c T atk_state_type_for_name
0000000000006e86 T atk_state_type_get_name
00000000000062dc T atk_state_type_get_type
0000000000006e80 T atk_state_type_register
0000000000006edc T atk_streamable_content_get_mime_type
0000000000006ed6 T atk_streamable_content_get_n_mime_types
0000000000006ee2 T atk_streamable_content_get_stream
0000000000006ed0 T atk_streamable_content_get_type
0000000000006ee8 T atk_streamable_content_get_uri
0000000000006f72 T atk_table_add_column_selection
0000000000006f66 T atk_table_add_row_selection
0000000000007023 T atk_table_cell_get_column_header_cells
000000000000701d T atk_table_cell_get_column_span
0000000000007029 T atk_table_cell_get_position
000000000000703b T atk_table_cell_get_row_column_span
0000000000007035 T atk_table_cell_get_row_header_cells
000000000000702f T atk_table_cell_get_row_span
0000000000007041 T atk_table_cell_get_table
0000000000006f84 T atk_table_cell_get_type
0000000000006f0c T atk_table_get_caption
0000000000006f06 T atk_table_get_column_at_index
0000000000006f18 T atk_table_get_column_description
0000000000006f1e T atk_table_get_column_extent_at
0000000000006f24 T atk_table_get_column_header
0000000000006efa T atk_table_get_index_at
0000000000006f12 T atk_table_get_n_columns
0000000000006f2a T atk_table_get_n_rows
0000000000006f00 T atk_table_get_row_at_index
0000000000006f30 T atk_table_get_row_description
0000000000006f36 T atk_table_get_row_extent_at
0000000000006f3c T atk_table_get_row_header
0000000000006f4e T atk_table_get_selected_columns
0000000000006f48 T atk_table_get_selected_rows
0000000000006f42 T atk_table_get_summary
0000000000006eee T atk_table_get_type
0000000000006f54 T atk_table_is_column_selected
0000000000006f5a T atk_table_is_row_selected
0000000000006f60 T atk_table_is_selected
0000000000006ef4 T atk_table_ref_at
0000000000006f78 T atk_table_remove_column_selection
0000000000006f6c T atk_table_remove_row_selection
0000000000006f7e T atk_table_set_caption
0000000000006f7f T atk_table_set_column_description
0000000000006f80 T atk_table_set_column_header
0000000000006f81 T atk_table_set_row_description
0000000000006f82 T atk_table_set_row_header
0000000000006f83 T atk_table_set_summary
000000000000709c T atk_text_add_selection
00000000000070c8 T atk_text_attribute_for_name
00000000000070c2 T atk_text_attribute_get_name
00000000000062e2 T atk_text_attribute_get_type
00000000000070ce T atk_text_attribute_get_value
00000000000070bc T atk_text_attribute_register
00000000000062e8 T atk_text_boundary_get_type
00000000000062f4 T atk_text_clip_type_get_type
00000000000070e0 T atk_text_free_ranges
00000000000070b5 T atk_text_get_bounded_ranges
0000000000007071 T atk_text_get_caret_offset
0000000000007053 T atk_text_get_character_at_offset
0000000000007084 T atk_text_get_character_count
0000000000007077 T atk_text_get_character_extents
000000000000707e T atk_text_get_default_attributes
0000000000007090 T atk_text_get_n_selections
000000000000708a T atk_text_get_offset_at_point
00000000000070b4 T atk_text_get_range_extents
0000000000007078 T atk_text_get_run_attributes
0000000000007096 T atk_text_get_selection
000000000000706b T atk_text_get_string_at_offset
000000000000704d T atk_text_get_text
0000000000007059 T atk_text_get_text_after_offset
000000000000705f T atk_text_get_text_at_offset
0000000000007065 T atk_text_get_text_before_offset
0000000000007047 T atk_text_get_type
00000000000062ee T atk_text_granularity_get_type
00000000000070a2 T atk_text_remove_selection
00000000000070d4 T atk_text_scroll_substring_to
00000000000070da T atk_text_scroll_substring_to_point
00000000000070ae T atk_text_set_caret_offset
00000000000070a8 T atk_text_set_selection
00000000000070e1 T atk_util_get_type
0000000000007124 T atk_value_get_current_value
0000000000007135 T atk_value_get_increment
0000000000007125 T atk_value_get_maximum_value
0000000000007127 T atk_value_get_minimum_increment
0000000000007126 T atk_value_get_minimum_value
000000000000712f T atk_value_get_range
000000000000713a T atk_value_get_sub_ranges
000000000000711e T atk_value_get_type
000000000000712e T atk_value_get_value_and_text
0000000000007128 T atk_value_set_current_value
0000000000007140 T atk_value_set_value
0000000000007147 T atk_value_type_get_localized_name
0000000000007141 T atk_value_type_get_name
0000000000006306 T atk_value_type_get_type
000000000000716b T atk_window_get_type
0000000000006d71 T _compact_name
                 U g_boxed_type_register_static
                 U g_cclosure_marshal_VOID__BOOLEAN
                 U g_cclosure_marshal_VOID__POINTER
                 U g_cclosure_marshal_VOID__UINT_POINTER
                 U g_cclosure_marshal_VOID__VOID
                 U g_dgettext
0000000000006598 T _gettext_initialization
                 U g_intern_static_string
                 U g_object_class_install_property
                 U g_once_init_enter
                 U g_once_init_leave
                 U g_param_spec_double
                 U g_param_spec_enum
                 U g_param_spec_int
                 U g_param_spec_object
                 U g_param_spec_string
                 U g_return_if_fail_warning
                 U g_signal_new
                 U g_type_add_instance_private
                 U g_type_check_instance_is_a
                 U g_type_class_adjust_private_offset
                 U g_type_class_peek_parent
                 U g_type_interface_add_prerequisite
                 U g_type_register_static
                 U g_type_register_static_simple

_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Wed Jun 07, 2023 7:03 pm    Post subject: Reply with quote

stefan11111 wrote:
Code:
                 U g_boxed_type_register_static
                 U g_cclosure_marshal_VOID__BOOLEAN
                 U g_cclosure_marshal_VOID__POINTER
                 U g_cclosure_marshal_VOID__UINT_POINTER
                 U g_cclosure_marshal_VOID__VOID
                 U g_dgettext
                 ...
                 U g_intern_static_string
                 U g_object_class_install_property
                 U g_once_init_enter
                 U g_once_init_leave
                 U g_param_spec_double
                 U g_param_spec_enum
                 U g_param_spec_int
                 U g_param_spec_object
                 U g_param_spec_string
                 U g_return_if_fail_warning
                 U g_signal_new
                 U g_type_add_instance_private
                 U g_type_check_instance_is_a
                 U g_type_class_adjust_private_offset
                 U g_type_class_peek_parent
                 U g_type_interface_add_prerequisite
                 U g_type_register_static
                 U g_type_register_static_simple

You have undefined symbols; your modified code must still have references to those functions / objects / whatever they are (from GLib maybe?).
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Wed Jun 07, 2023 7:11 pm    Post subject: Reply with quote

GDH-gentoo wrote:

You have undefined symbols; your modified code must still have references to those functions / objects / whatever they are (from GLib maybe?).

You mean the U 's?
The unmodified atk has plenty of those too.
Code:
                 w __cxa_finalize@GLIBC_2.2.5
                 U dcgettext@GLIBC_2.2.5
                 U g_array_append_vals
                 U g_array_remove_index
                 U g_array_sized_new
                 U g_assertion_message_expr
                 U g_boxed_type_register_static
                 U g_cclosure_marshal_VOID__BOOLEAN
                 U g_cclosure_marshal_VOID__BOXED
                 U g_cclosure_marshal_VOID__INT
                 U g_cclosure_marshal_VOID__POINTER
                 U g_cclosure_marshal_VOID__UINT_POINTER
                 U g_cclosure_marshal_VOID__VOID
                 U g_dgettext
                 U g_enum_get_value
                 U g_enum_get_value_by_nick
                 U g_enum_register_static
                 U g_flags_register_static
                 U g_free
                 U g_hash_table_destroy
                 U g_hash_table_insert
                 U g_hash_table_lookup
                 U g_hash_table_new
                 U g_hash_table_new_full
                 U g_hash_table_remove
                 U g_int_equal
                 U g_intern_static_string
                 U g_int_hash
                 U g_log_structured_standard
                 U g_malloc
                 U g_malloc0
                 w __gmon_start__
                 U g_object_class_install_property
                 U g_object_get_property
                 U g_object_get_qdata
                 U g_object_new
                 U g_object_notify
                 U g_object_ref
                 U g_object_set_qdata
                 U g_object_unref
                 U g_object_weak_ref
                 U g_object_weak_unref
                 U g_once_init_enter
                 U g_once_init_leave
                 U g_param_spec_boolean
                 U g_param_spec_double
                 U g_param_spec_enum
                 U g_param_spec_int
                 U g_param_spec_object
                 U g_param_spec_string
                 U g_param_spec_value_array
                 U g_ptr_array_add
                 U g_ptr_array_free
                 U g_ptr_array_new
                 U g_ptr_array_remove
                 U g_ptr_array_sized_new
                 U g_quark_from_static_string
                 U g_quark_from_string
                 U g_realloc
                 U g_return_if_fail_warning
                 U g_signal_add_emission_hook
                 U g_signal_emit
                 U g_signal_lookup
                 U g_signal_new
                 U g_signal_remove_emission_hook
                 U g_slice_alloc
                 U g_slice_free1
                 U g_slist_free
                 U g_strdup
                 U g_strfreev
                 U g_strsplit
                 U g_strv_length
                 U g_type_add_instance_private
                 U g_type_add_interface_static
                 U g_type_check_class_is_a
                 U g_type_check_instance_is_a
                 U g_type_check_instance_is_fundamentally_a
                 U g_type_check_value
                 U g_type_class_adjust_private_offset
                 U g_type_class_peek
                 U g_type_class_peek_parent
                 U g_type_class_ref
                 U g_type_class_unref
                 U g_type_create_instance
                 U g_type_free_instance
                 U g_type_from_name
                 U g_type_interface_add_prerequisite
                 U g_type_interface_peek
                 U g_type_name
                 U g_type_parent
                 U g_type_register_static
                 U g_type_register_static_simple
                 U g_utf8_strlen
                 U g_value_array_append
                 U g_value_array_free
                 U g_value_array_get_nth
                 U g_value_array_new
                 U g_value_get_boxed
                 U g_value_get_enum
                 U g_value_get_object
                 U g_value_get_string
                 U g_value_init
                 U g_value_peek_pointer
                 U g_value_set_boolean
                 U g_value_set_boxed
                 U g_value_set_enum
                 U g_value_set_int
                 U g_value_set_object
                 U g_value_set_string
                 U g_value_unset
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 U setlocale@GLIBC_2.2.5
                 U __stack_chk_fail@GLIBC_2.4
                 U strcmp@GLIBC_2.2.5

_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Wed Jun 07, 2023 7:20 pm    Post subject: Reply with quote

stefan11111 wrote:
You mean the U 's?

Yup.

stefan11111 wrote:
The unmodified atk has plenty of those too.

It has more, but more importantly, it specifies the set of shared libraries that should provide corresponding definitions because it was properly linked:

stefan11111 wrote:
Code:
/usr/lib64/libatk-1.0.so.0.bak:
        linux-vdso.so.1 (0x00007ffe2bfbc000)
        libglib-2.0.so.0 => /usr/lib64/libglib-2.0.so.0 (0x00007f93d5579000)
        libgobject-2.0.so.0 => /usr/lib64/libgobject-2.0.so.0 (0x00007f93d5518000)
        libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f93d547c000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f93d52a9000)
        libffi.so.8 => /usr/lib64/libffi.so.8 (0x00007f93d529e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f93d56e0000)

If you are going to use -nostdlib, you can't have undefined symbols. Not a single one.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Wed Jun 07, 2023 9:47 pm    Post subject: Reply with quote

Shouldn't those undefined symbols cause a linker error when building the shared library?
If I try to build something like this:
Code:
void main()
{
    __asm__(".globl _start\n"
            "_start:"
           );
    printf("Hello world!\n");
}

It fails with a linker error:
Code:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cc3S4PKG.o: in function `_start':
ttt.c:(.text+0xf): undefined reference to `puts'
collect2: error: ld returned 1 exit status


What is going to happen if one of those undefined symbols gets called? Segfault?
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21852

PostPosted: Wed Jun 07, 2023 10:12 pm    Post subject: Reply with quote

Undefined symbols in a shared library may or may not be fatal at link time, depending on whether the linker was told to make them fatal. If not fatal at link time, then they will be fatal at resolution time if no defined symbol can be found for them.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Wed Jun 07, 2023 11:32 pm    Post subject: Reply with quote

stefan11111 wrote:
What is going to happen if one of those undefined symbols gets called? Segfault?

What Hu said. A link failure.

I did some tests with GCC. It will let you create a shared library without complaints:

Code:
$ cat test1.c
int some_other_function(void);

int some_function() {
   return some_other_function();
}

$ gcc -fPIC -shared -Wl,-soname=test.so -nostdlib -o test.so test1.c && echo No problems here
No problems here

$ objdump -p test.so

test.so:     file format elf64-x86-64

Program Header:
...

Dynamic Section:
  SONAME               test.so
  GNU_HASH             0x0000000000000270
  STRTAB               0x00000000000002e0
  SYMTAB               0x0000000000000298
  STRSZ                0x000000000000002b
  SYMENT               0x0000000000000018
  PLTGOT               0x0000000000004000
  PLTRELSZ             0x0000000000000018
  PLTREL               0x0000000000000007
  JMPREL               0x0000000000000310

$ nm -D test.so
0000000000001020 T some_function
                 U some_other_function

It won't let you create an executable linked to such a library.

Code:
$ cat test2.c
int some_function(void);

int main() {
   return some_function();
}

$ gcc -o test test2.c test.so
/usr/bin/ld: test.so: undefined reference to `some_other_function'
collect2: error: ld returned 1 exit status

_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Wed Jun 14, 2023 10:59 am    Post subject: Reply with quote

I looked a bit into different compiler optimization levels:
Here is what one empty function looks like.
With -O1, it produces this code, which is inefficient:
Code:
    5090:       b8 00 00 00 00          mov    $0x0,%eax
    5095:       c3                      ret

With -Os, it produces the xor(efficient) version of this:
Code:
    5090:       31 c0                   xor    %eax,%eax
    5092:       c3                      ret

With -O2, -O3 and -Ofast, it adds some more stuff which I have no idea what it does:
Code:
    5090:       31 c0                   xor    %eax,%eax
    5092:       c3                      ret
    5093:       66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
    509a:       00 00 00 00
    509e:       66 90                   xchg   %ax,%ax

What's this about? Also, isn't everything after ret ignored?

Also, I removed most of the undefined symbols.
These are the one I am left with as of now:
Code:
                 U g_object_class_install_property
                 U g_param_spec_object
                 U g_param_spec_string
                 U g_type_add_instance_private
                 U g_type_class_adjust_private_offset
                 U g_type_class_peek_parent
                 U g_type_register_static

If I leave them undefined and just live with that emerge warning, will there be any problems?
If programs will just fail with a linker warning if they are not linked against glib, there is no way to introduce other problems, like segfaults and security vulnerabilities.
It seems like the useful part of atk can be reduced to:
Code:
static void bloat()
{
}

long unsigned int
atk_object_get_type (void)
{
  static long unsigned int type = 0;

  if (!type)
    {
      static const GTypeInfo typeInfo =
      {
        sizeof (AtkObjectClass),
        0,
        0,
        atk_object_class_init,
        0,
        0,
        sizeof (AtkObject),
        0,
        bloat,
      } ;
      type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;

      AtkObject_private_offset =
        g_type_add_instance_private (type, sizeof (AtkObjectPrivate));
    }
  return type;
}

static inline void*
atk_object_get_instance_private (AtkObject *self)
{
  return (G_STRUCT_MEMBER_P (self, AtkObject_private_offset));
}

static void
atk_object_class_init (AtkObjectClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  parent_class = g_type_class_peek_parent (klass);

  if (AtkObject_private_offset != 0)
    g_type_class_adjust_private_offset (klass, &AtkObject_private_offset);

  gobject_class->set_property = bloat;
  gobject_class->get_property = bloat;
  gobject_class->finalize = bloat;
  gobject_class->notify = bloat;

  klass->get_name = bloat;
  klass->get_description = bloat;
  klass->get_parent = bloat;
  klass->get_n_children = 0;
  klass->ref_child = 0;
  klass->get_index_in_parent = 0;
  klass->ref_relation_set = bloat;
  klass->get_role = bloat;
  klass->get_layer = bloat;
  klass->get_mdi_zorder = 0;
  klass->initialize = bloat;
  klass->ref_state_set = bloat;
  klass->set_name = bloat;
  klass->set_description = bloat;
  klass->set_parent = bloat;
  klass->set_role = bloat;
  klass->get_object_locale = bloat;

  /*
   * We do not define default signal handlers here
   */
  klass->children_changed = 0;
  klass->focus_event = 0;
  klass->property_change = 0;
  klass->visible_data_changed = 0;
  klass->active_descendant_changed = 0;

  g_object_class_install_property (gobject_class,
                                   PROP_NAME,
                                   g_param_spec_string (atk_object_name_property_name,
                                                        0,
                                                        0,
                                                        0,
                                                        G_PARAM_READWRITE));
  g_object_class_install_property (gobject_class,
                                   PROP_PARENT,
                                   g_param_spec_object (atk_object_name_property_parent,
                                                        0,
                                                        0,
                                                        ATK_TYPE_OBJECT,
                                                        G_PARAM_READWRITE));
}

_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Thu Jun 15, 2023 9:37 am    Post subject: Reply with quote

stefan11111 wrote:
I If I leave them undefined and just live with that emerge warning, will there be any problems?

Yes, see posts above yours.

stefan11111 wrote:
If programs will just fail with a linker warning if they are not linked against glib, there is no way to introduce other problems, like segfaults and security vulnerabilities.

Not warning, fatal failure. The build is aborted and you end up with no program at all.

stefan11111 wrote:
It seems like the useful part of atk can be reduced to:
Code:
...

Yeah. bloat() contains the important part :-P
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Thu Jun 15, 2023 11:49 am    Post subject: Reply with quote

The more I look into Glib, the more I hate it:
Code:
struct  _GObjectClass
{
  GTypeClass   g_type_class;

  /*< private >*/
  GSList      *construct_properties;

  /*< public >*/
  /* seldom overridden */
  GObject*   (*constructor)     (GType                  type,
                                 guint                  n_construct_properties,
                                 GObjectConstructParam *construct_properties);
  /* overridable methods */
  void       (*set_property)            (GObject        *object,
                                         guint           property_id,
                                         const GValue   *value,
                                         GParamSpec     *pspec);
  void       (*get_property)            (GObject        *object,
                                         guint           property_id,
                                         GValue         *value,
                                         GParamSpec     *pspec);
  void       (*dispose)                 (GObject        *object);
  void       (*finalize)                (GObject        *object);
  /* seldom overridden */
  void       (*dispatch_properties_changed) (GObject      *object,
                                             guint         n_pspecs,
                                             GParamSpec  **pspecs);
  /* signals */
  void       (*notify)                  (GObject        *object,
                                         GParamSpec     *pspec);

  /* called when done constructing */
  void       (*constructed)             (GObject        *object);

  /*< private >*/
  gsize         flags;

  gsize         n_construct_properties;

  gpointer pspecs;
  gsize n_pspecs;

  /* padding */
  gpointer      pdummy[3];
};

Code:
typedef struct _GTypeClass              GTypeClass;

Code:
struct _GTypeClass
{
  /*< private >*/
  GType g_type;
};

Code:
typedef gsize GType;

Code:
typedef unsigned long gsize;

So GObjectClass is struct _GObjectClass which has a member of type GTypeClass which is struct _GTypeClass which only has a member of type GType which is gsize which is unsigned long.
Why?
Why everything is scattered across so many files with so many levels of opacity?
Why does that struct have 3 pointer of padding? It's not like when people add char[n] to make use of padding that is already there. This is just there to waste memory.
Why do we need a typedef for a struct with a single member?
And worst of all, why do this travesty with function pointers? What is wrong with having functions and structs separate?
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1569
Location: South America

PostPosted: Thu Jun 15, 2023 2:51 pm    Post subject: Reply with quote

stefan11111 wrote:
Why?
Why everything is scattered across so many files with so many levels of opacity?
Why does that struct have 3 pointer of padding? It's not like when people add char[n] to make use of padding that is already there. This is just there to waste memory.
Why do we need a typedef for a struct with a single member?
And worst of all, why do this travesty with function pointers? What is wrong with having functions and structs separate?

That's how object-oriented programming style in a language that doesn't support it natively ends up looking like. It's support for classes and objects of class types 'hand-compiled' by a programmer to something that can be expressed in C.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Thu Jun 15, 2023 3:22 pm    Post subject: Reply with quote

GDH-gentoo wrote:
stefan11111 wrote:
Why?
Why everything is scattered across so many files with so many levels of opacity?
Why does that struct have 3 pointer of padding? It's not like when people add char[n] to make use of padding that is already there. This is just there to waste memory.
Why do we need a typedef for a struct with a single member?
And worst of all, why do this travesty with function pointers? What is wrong with having functions and structs separate?

That's how object-oriented programming style in a language that doesn't support it natively ends up looking like. It's support for classes and objects of class types 'hand-compiled' by a programmer to something that can be expressed in C.

That explains the function pointers, but why the typedefs? Why the extra 3 pointers of wasted space? Why all the wasted space? You don't need so much space and so many types.
Code:
typedef gint   gboolean;

Why waste 4 bytes on a bool? Why define all these new types? What did the standard ones not accomplish?
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
sMueggli
Guru
Guru


Joined: 03 Sep 2022
Posts: 378

PostPosted: Thu Jun 15, 2023 4:00 pm    Post subject: Reply with quote

stefan11111 wrote:

Code:
typedef gint   gboolean;

Why waste 4 bytes on a bool? Why define all these new types? What did the standard ones not accomplish?


Why do you think, that 4 bytes are wasted for a bool? On a x86_64 system, the cpu register has a size of 64 bits and 4 bytes occupy only 32 bit (if one byte is defined as 8 bit).

I guess it is easier to change typedefs in a project.

And what are "the standard ones" for you?
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 1707

PostPosted: Thu Jun 15, 2023 4:03 pm    Post subject: Reply with quote

glib also predates C99. They're working on moving to standard types too (https://gitlab.gnome.org/GNOME/glib/-/issues/1484). _Bool vs int can also affect ABI.
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Thu Jun 15, 2023 4:51 pm    Post subject: Reply with quote

sMueggli wrote:
stefan11111 wrote:

Code:
typedef gint   gboolean;

Why waste 4 bytes on a bool? Why define all these new types? What did the standard ones not accomplish?


Why do you think, that 4 bytes are wasted for a bool? On a x86_64 system, the cpu register has a size of 64 bits and 4 bytes occupy only 32 bit (if one byte is defined as 8 bit).

Try it on x86_64:
Code:
int main() {
    printf("%d\n", sizeof(int));
    return 0;
}


gint is a int, not a pointer;
sMueggli wrote:

And what are "the standard ones" for you?

These:
https://en.wikipedia.org/wiki/C_data_types
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
sMueggli
Guru
Guru


Joined: 03 Sep 2022
Posts: 378

PostPosted: Fri Jun 16, 2023 9:57 am    Post subject: Reply with quote

Ok, I was digging a bit deeper.

With the Makefile
Code:
all: booleans_bin booleans_opt

booleans_bin: booleans.c
   gcc -o booleans -Wall -Wpedantic booleans.c

booleans_opt: booleans.c
   gcc -o booleans_opt -Wall -Wpedantic -O3 booleans.c

clean:
   rm -rf *.o *~


and the code
Code:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {

  typedef int gint;
  typedef gint gboolean;

  bool stdbool = 2 == argc;
  gboolean glibbool = 3 == argc;

  if (stdbool) {
    puts("2");
  }

  if (glibbool) {
    puts("3");
  }

  return EXIT_SUCCESS;
}


Using radare2 resulted in
Code:
            ; DATA XREF from entry0 @ 0x1064(r)
┌ 87: int main (uint32_t argc, char **argv);
│           ; arg uint32_t argc @ rdi
│           ; arg char **argv @ rsi
│           ; var uint32_t var_4h @ rbp-0x4
│           ; var uint32_t var_5h @ rbp-0x5
│           ; var uint32_t var_14h @ rbp-0x14
│           ; var char **var_20h @ rbp-0x20
│           0x00001165      55             push rbp
│           0x00001166      4889e5         mov rbp, rsp
│           0x00001169      4883ec20       sub rsp, 0x20
│           0x0000116d      897dec         mov dword [var_14h], edi    ; argc
│           0x00001170      488975e0       mov qword [var_20h], rsi    ; argv
│           0x00001174      837dec02       cmp dword [var_14h], 2
│           0x00001178      0f94c0         sete al
│           0x0000117b      8845fb         mov byte [var_5h], al
│           0x0000117e      837dec03       cmp dword [var_14h], 3
│           0x00001182      0f94c0         sete al
│           0x00001185      0fb6c0         movzx eax, al
│           0x00001188      8945fc         mov dword [var_4h], eax
│           0x0000118b      807dfb00       cmp byte [var_5h], 0
│       ┌─< 0x0000118f      740f           je 0x11a0
│       │   0x00001191      488d056c0e00.  lea rax, [0x00002004]       ; u"23\u1b01\u3b03,"
│       │   0x00001198      4889c7         mov rdi, rax                ; const char *s
│       │   0x0000119b      e890feffff     call sym.imp.puts           ; int puts(const char *s)
│       │   ; CODE XREF from main @ 0x118f(x)
│       └─> 0x000011a0      837dfc00       cmp dword [var_4h], 0
│       ┌─< 0x000011a4      740f           je 0x11b5
│       │   0x000011a6      488d05590e00.  lea rax, [0x00002006]       ; "3"
│       │   0x000011ad      4889c7         mov rdi, rax                ; const char *s
│       │   0x000011b0      e87bfeffff     call sym.imp.puts           ; int puts(const char *s)
│       │   ; CODE XREF from main @ 0x11a4(x)
│       └─> 0x000011b5      b800000000     mov eax, 0
│           0x000011ba      c9             leave
└           0x000011bb      c3             ret


and
Code:
            ;-- section..text:
            ; DATA XREF from entry0 @ 0x10a4(r)
┌ 49: int main (uint32_t argc);
│           ; arg uint32_t argc @ rdi
│           0x00001050      4883ec08       sub rsp, 8                  ; [14] -r-x section size 341 named .text
│           0x00001054      83ff02         cmp edi, 2                  ; argc
│       ┌─< 0x00001057      740c           je 0x1065
│       │   0x00001059      83ff03         cmp edi, 3                  ; argc
│      ┌──< 0x0000105c      7415           je 0x1073
│      ││   ; CODE XREFS from main @ 0x1071(x), 0x107f(x)
│    ┌┌───> 0x0000105e      31c0           xor eax, eax
│    ╎╎││   0x00001060      4883c408       add rsp, 8
│    ╎╎││   0x00001064      c3             ret
│    ╎╎││   ; CODE XREF from main @ 0x1057(x)
│    ╎╎│└─> 0x00001065      488d3d980f00.  lea rdi, [0x00002004]       ; u"23\u1b01\u3b03," ; const char *s
│    ╎╎│    0x0000106c      e8bfffffff     call sym.imp.puts           ; int puts(const char *s)
│    └────< 0x00001071      ebeb           jmp 0x105e
│     ╎│    ; CODE XREF from main @ 0x105c(x)
│     ╎└──> 0x00001073      488d3d8c0f00.  lea rdi, [0x00002006]       ; "3" ; const char *s
│     ╎     0x0000107a      e8b1ffffff     call sym.imp.puts           ; int puts(const char *s)
└     └───< 0x0000107f      ebdd           jmp 0x105e


And indeed, the "normal" compiled binary contains one instruction more for the "gboolean" part:
Code:
0x00001185      0fb6c0         movzx eax, al

I am not sure, but I guess, the performance of "mov byte trgt, src" and "mov dword trgt,src" is the same.

The "optimised" binary though does not contain a trace of the local variables. So there is no waste of "bytes".
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 922
Location: Romania

PostPosted: Fri Jun 16, 2023 10:26 am    Post subject: Reply with quote

Yours is a very specific use case of gboolean.
I can live with 3 bytes of wasted memory.
but what if I create a struct with a few gboolean members? Maybe a linked list with such elements.
It's not just about 3 bytes. They add up.

And also, why those 3 pointers of padding in struct _GObjectClass?
Those aren't three bytes, on amd64 those are 24 bytes for each GObjectClass element. That really adds up. and it's a waste of space.
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
sMueggli
Guru
Guru


Joined: 03 Sep 2022
Posts: 378

PostPosted: Fri Jun 16, 2023 1:27 pm    Post subject: Reply with quote

stefan11111 wrote:
Yours is a very specific use case of gboolean.

Yes, indeed.

stefan11111 wrote:

I can live with 3 bytes of wasted memory.
but what if I create a struct with a few gboolean members? Maybe a linked list with such elements.
It's not just about 3 bytes. They add up.


If you are creating a struct, you are also responsible for the memory layout/alignment. If you take gbooleans, you might have your reasons (readability, ease of maintenance...). But you can also choose another approach which is more "resource-friendly" in one or another way.

Depending on the elements and the order, a struct may use more space due to padding.

stefan11111 wrote:

And also, why those 3 pointers of padding in struct _GObjectClass?
Those aren't three bytes, on amd64 those are 24 bytes for each GObjectClass element. That really adds up. and it's a waste of space.


I am not a C programmer and also not using glib. So I do not have any practical experience in this regard.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum