Sublime Forum

How is dlopen called by Sublime Text?

#1

On NixOS Linux distribution, we do not have FHS so, to allow Sublime to find pkexec, we load libredirect through LD_PRELOAD, replacing symbols related to opening files with our own. Recently, I have added support for dlopen but this broke Sublime:

Unable to load cairo_clip from libcairo.so
Unable to load cairo_create from libcairo.so
Unable to load cairo_destroy from libcairo.so
Unable to load cairo_fill from libcairo.so
Unable to load cairo_font_options_create from libcairo.so
Unable to load cairo_font_options_destroy from libcairo.so
Unable to load cairo_font_options_set_antialias from libcairo.so
Unable to load cairo_get_source from libcairo.so
Unable to load cairo_image_surface_create from libcairo.so
Unable to load cairo_image_surface_create_for_data from libcairo.so
Unable to load cairo_image_surface_get_data from libcairo.so
Unable to load cairo_image_surface_get_format from libcairo.so
Unable to load cairo_image_surface_get_height from libcairo.so
Unable to load cairo_image_surface_get_stride from libcairo.so
Unable to load cairo_image_surface_get_width from libcairo.so
Unable to load cairo_line_to from libcairo.so
Unable to load cairo_matrix_init_scale from libcairo.so
Unable to load cairo_matrix_init_translate from libcairo.so
Unable to load cairo_matrix_translate from libcairo.so
Unable to load cairo_move_to from libcairo.so
Unable to load cairo_paint_with_alpha from libcairo.so
Unable to load cairo_pattern_set_extend from libcairo.so
Unable to load cairo_pattern_set_matrix from libcairo.so
Unable to load cairo_rectangle from libcairo.so
Unable to load cairo_reset_clip from libcairo.so
Unable to load cairo_restore from libcairo.so
Unable to load cairo_save from libcairo.so
Unable to load cairo_set_line_width from libcairo.so
Unable to load cairo_set_operator from libcairo.so
Unable to load cairo_set_source_rgb from libcairo.so
Unable to load cairo_set_source_rgba from libcairo.so
Unable to load cairo_set_source_surface from libcairo.so
Unable to load cairo_stroke from libcairo.so
Unable to load cairo_surface_destroy from libcairo.so
Unable to load cairo_surface_flush from libcairo.so
Unable to load cairo_translate from libcairo.so
Unable to load cairo_scale from libcairo.so
Unable to load cairo_copy_clip_rectangle_list from libcairo.so
Unable to load cairo_rectangle_list_destroy from libcairo.so
Unable to load cairo_ft_scaled_font_lock_face from libcairo.so
Unable to load cairo_ft_scaled_font_unlock_face from libcairo.so
Unable to load pango_font_description_free from libpango-1.0.so
Unable to load pango_font_description_new from libpango-1.0.so
Unable to load pango_font_describe from libpango-1.0.so
Unable to load pango_font_face_describe from libpango-1.0.so
Unable to load pango_font_face_is_synthesized from libpango-1.0.so
Unable to load pango_font_description_set_family from libpango-1.0.so
Unable to load pango_font_description_get_family from libpango-1.0.so
Unable to load pango_font_description_set_size from libpango-1.0.so
Unable to load pango_font_description_set_style from libpango-1.0.so
Unable to load pango_font_description_set_weight from libpango-1.0.so
Unable to load pango_font_description_get_weight from libpango-1.0.so
Unable to load pango_font_get_metrics from libpango-1.0.so
Unable to load pango_font_map_load_font from libpango-1.0.so
Unable to load pango_font_metrics_get_ascent from libpango-1.0.so
Unable to load pango_font_metrics_get_descent from libpango-1.0.so
Unable to load pango_font_metrics_unref from libpango-1.0.so
Unable to load pango_language_get_default from libpango-1.0.so
Unable to load pango_layout_get_context from libpango-1.0.so
Unable to load pango_layout_get_pixel_extents from libpango-1.0.so
Unable to load pango_layout_set_font_description from libpango-1.0.so
Unable to load pango_layout_set_text from libpango-1.0.so
Unable to load pango_cairo_context_set_font_options from libpangocairo-1.0.so
Unable to load pango_cairo_create_layout from libpangocairo-1.0.so
Unable to load pango_font_map_create_context from libpangocairo-1.0.so
Unable to load pango_cairo_font_map_get_default from libpangocairo-1.0.so
Unable to load pango_font_map_list_families from libpangocairo-1.0.so
Unable to load pango_font_family_get_name from libpangocairo-1.0.so
Unable to load pango_font_family_list_faces from libpangocairo-1.0.so
Unable to load pango_font_face_get_face_name from libpangocairo-1.0.so
Unable to load pango_cairo_show_layout from libpangocairo-1.0.so
Unable to load pango_cairo_update_layout from libpangocairo-1.0.so
Unable to load pango_layout_new from libpango-1.0.so
Unable to load pango_layout_get_iter from libpango-1.0.so
Unable to load pango_layout_iter_get_run_readonly from libpango-1.0.so
Unable to load pango_layout_iter_next_run from libpango-1.0.so
Unable to load pango_layout_iter_free from libpango-1.0.so
Unable to load pango_cairo_font_get_scaled_font from libpangocairo-1.0.so
Unable to load cairo_set_scaled_font from libcairo.so
Unable to load cairo_set_font_options from libcairo.so
Unable to load cairo_show_glyphs from libcairo.so
Unable to load pango_attr_list_new from libpango-1.0.so
Unable to load pango_attr_list_unref from libpango-1.0.so
Unable to load pango_attr_list_insert from libpango-1.0.so
Unable to load pango_layout_set_attributes from libpango-1.0.so
Unable to load FT_Load_Glyph from libfreetype.so
Unable to load libgdk-3.so
Unable to load gdk_cairo_create from libgdk-3.0.so
Unable to load gdk_cairo_get_clip_rectangle from libgdk-3.0.so
Unable to load gdk_cursor_new_for_display from libgdk-3.0.so
Unable to load gdk_cursor_unref from libgdk-3.0.so
Unable to load gdk_display_get_default from libgdk-3.0.so
Unable to load gdk_display_get_pointer from libgdk-3.0.so
Unable to load gdk_error_trap_pop from libgdk-3.0.so
Unable to load gdk_error_trap_push from libgdk-3.0.so
Unable to load gdk_keymap_get_for_display from libgdk-3.0.so
Unable to load gdk_keymap_translate_keyboard_state from libgdk-3.0.so
Unable to load gdk_keyval_to_unicode from libgdk-3.0.so
Unable to load gdk_pixbuf_new_from_file from libgdk-3.0.so
Unable to load gdk_screen_get_default from libgdk-3.0.so
Unable to load gdk_screen_get_display from libgdk-3.0.so
Unable to load gdk_screen_get_height from libgdk-3.0.so
Unable to load gdk_screen_get_root_window from libgdk-3.0.so
Unable to load gdk_screen_get_width from libgdk-3.0.so
Unable to load gdk_screen_get_n_monitors from libgdk-3.0.so
Unable to load gdk_screen_get_monitor_at_point from libgdk-3.0.so
Unable to load gdk_screen_get_monitor_geometry from libgdk-3.0.so
Unable to load gdk_screen_get_resolution from libgdk-3.0.so
Unable to load gdk_screen_get_rgba_visual from libgdk-3.0.so
Unable to load gdk_unicode_to_keyval from libgdk-3.0.so
Unable to load gdk_window_get_frame_extents from libgdk-3.0.so
Unable to load gdk_window_get_origin from libgdk-3.0.so
Unable to load gdk_window_get_state from libgdk-3.0.so
Unable to load gdk_window_invalidate_rect from libgdk-3.0.so
Unable to load gdk_window_set_cursor from libgdk-3.0.so
Unable to load gdk_window_move_resize from libgdk-3.0.so
Unable to load gdk_x11_display_get_type from libgdk-3.0.so
Unable to load gdk_x11_display_get_xdisplay from libgdk-3.0.so
Unable to load gdk_x11_window_get_xid from libgdk-3.0.so
Unable to load gdk_x11_get_server_time from libgdk-3.0.so
Unable to load gdk_x11_get_xatom_by_name_for_display from libgdk-3.0.so
Unable to load gdk_x11_window_set_user_time from libgdk-3.0.so
Unable to load gdk_window_get_width from libgdk-3.0.so
Unable to load gdk_window_get_height from libgdk-3.0.so
Unable to load libgtk-3.so
Unable to load gtk_accel_group_new from libgtk-3.so
Unable to load gtk_accelerator_get_default_mod_mask from libgtk-3.so
Unable to load gtk_box_get_type from libgtk-3.so
Unable to load gtk_box_pack_start from libgtk-3.so
Unable to load gtk_drawing_area_new from libgtk-3.so
Unable to load gtk_check_menu_item_get_type from libgtk-3.so
Unable to load gtk_check_menu_item_new_with_label from libgtk-3.so
Unable to load gtk_check_menu_item_set_active from libgtk-3.so
Unable to load gtk_clipboard_clear from libgtk-3.so
Unable to load gtk_clipboard_get from libgtk-3.so
Unable to load gtk_clipboard_set_text from libgtk-3.so
Unable to load gtk_clipboard_set_with_data from libgtk-3.so
Unable to load gtk_clipboard_store from libgtk-3.so
Unable to load gtk_clipboard_wait_for_text from libgtk-3.so
Unable to load gtk_container_add from libgtk-3.so
Unable to load gtk_container_get_children from libgtk-3.so
Unable to load gtk_container_get_type from libgtk-3.so
Unable to load gtk_container_remove from libgtk-3.so
Unable to load gtk_dialog_add_button from libgtk-3.so
Unable to load gtk_dialog_get_type from libgtk-3.so
Unable to load gtk_dialog_run from libgtk-3.so
Unable to load gtk_dialog_set_default_response from libgtk-3.so
Unable to load gtk_drag_dest_set from libgtk-3.so
Unable to load gtk_drag_finish from libgtk-3.so
Unable to load gtk_file_chooser_add_filter from libgtk-3.so
Unable to load gtk_file_chooser_dialog_new from libgtk-3.so
Unable to load gtk_file_chooser_get_filename from libgtk-3.so
Unable to load gtk_file_chooser_get_files from libgtk-3.so
Unable to load gtk_file_chooser_get_type from libgtk-3.so
Unable to load gtk_file_chooser_set_current_folder from libgtk-3.so
Unable to load gtk_file_chooser_set_current_name from libgtk-3.so
Unable to load gtk_file_chooser_set_do_overwrite_confirmation from libgtk-3.so
Unable to load gtk_file_chooser_set_local_only from libgtk-3.so
Unable to load gtk_file_chooser_set_select_multiple from libgtk-3.so
Unable to load gtk_file_filter_add_pattern from libgtk-3.so
Unable to load gtk_file_filter_new from libgtk-3.so
Unable to load gtk_file_filter_set_name from libgtk-3.so
Unable to load gtk_get_current_event_time from libgtk-3.so
Unable to load gtk_im_context_filter_keypress from libgtk-3.so
Unable to load gtk_im_context_focus_in from libgtk-3.so
Unable to load gtk_im_context_focus_out from libgtk-3.so
Unable to load gtk_im_context_set_client_window from libgtk-3.so
Unable to load gtk_im_context_set_cursor_location from libgtk-3.so
Unable to load gtk_im_context_set_use_preedit from libgtk-3.so
Unable to load gtk_im_multicontext_new from libgtk-3.so
Unable to load gtk_init from libgtk-3.so
Unable to load gtk_init_check from libgtk-3.so
Unable to load gtk_main from libgtk-3.so
Unable to load gtk_main_quit from libgtk-3.so
Unable to load gtk_menu_attach_to_widget from libgtk-3.so
Unable to load gtk_menu_bar_new from libgtk-3.so
Unable to load gtk_menu_get_type from libgtk-3.so
Unable to load gtk_menu_item_get_label from libgtk-3.so
Unable to load gtk_menu_item_get_submenu from libgtk-3.so
Unable to load gtk_menu_item_get_type from libgtk-3.so
Unable to load gtk_menu_item_new_with_label from libgtk-3.so
Unable to load gtk_menu_item_set_label from libgtk-3.so
Unable to load gtk_menu_item_set_submenu from libgtk-3.so
Unable to load gtk_menu_item_set_use_underline from libgtk-3.so
Unable to load gtk_menu_new from libgtk-3.so
Unable to load gtk_menu_popup from libgtk-3.so
Unable to load gtk_menu_shell_append from libgtk-3.so
Unable to load gtk_menu_shell_get_type from libgtk-3.so
Unable to load gtk_message_dialog_new from libgtk-3.so
Unable to load gtk_message_dialog_new_with_markup from libgtk-3.so
Unable to load gtk_selection_data_get_uris from libgtk-3.so
Unable to load gtk_selection_data_get_format from libgtk-3.so
Unable to load gtk_selection_data_get_length from libgtk-3.so
Unable to load gtk_selection_data_set_text from libgtk-3.so
Unable to load gtk_separator_menu_item_new from libgtk-3.so
Unable to load gtk_settings_get_default from libgtk-3.so
Unable to load gtk_show_uri from libgtk-3.so
Unable to load gtk_vbox_new from libgtk-3.so
Unable to load gtk_widget_add_accelerator from libgtk-3.so
Unable to load gtk_widget_add_events from libgtk-3.so
Unable to load gtk_widget_destroy from libgtk-3.so
Unable to load gtk_widget_get_display from libgtk-3.so
Unable to load gtk_widget_get_parent from libgtk-3.so
Unable to load gtk_widget_get_screen from libgtk-3.so
Unable to load gtk_widget_get_type from libgtk-3.so
Unable to load gtk_widget_get_window from libgtk-3.so
Unable to load gtk_widget_grab_focus from libgtk-3.so
Unable to load gtk_widget_hide from libgtk-3.so
Unable to load gtk_widget_remove_accelerator from libgtk-3.so
Unable to load gtk_widget_set_app_paintable from libgtk-3.so
Unable to load gtk_widget_set_double_buffered from libgtk-3.so
Unable to load gtk_widget_set_sensitive from libgtk-3.so
Unable to load gtk_widget_set_visual from libgtk-3.so
Unable to load gtk_widget_show from libgtk-3.so
Unable to load gtk_widget_show_all from libgtk-3.so
Unable to load gtk_widget_size_request from libgtk-3.so
Unable to load gtk_widget_get_preferred_height from libgtk-3.so
Unable to load gtk_widget_get_allocation from libgtk-3.so
Unable to load gtk_widget_get_allocated_width from libgtk-3.so
Unable to load gtk_widget_get_allocated_height from libgtk-3.so
Unable to load gtk_widget_get_scale_factor from libgtk-3.so
Unable to load gtk_window_add_accel_group from libgtk-3.so
Unable to load gtk_window_fullscreen from libgtk-3.so
Unable to load gtk_window_get_type from libgtk-3.so
Unable to load gtk_window_iconify from libgtk-3.so
Unable to load gtk_window_maximize from libgtk-3.so
Unable to load gtk_window_move from libgtk-3.so
Unable to load gtk_window_new from libgtk-3.so
Unable to load gtk_window_present from libgtk-3.so
Unable to load gtk_window_present_with_time from libgtk-3.so
Unable to load gtk_window_remove_accel_group from libgtk-3.so
Unable to load gtk_window_resize from libgtk-3.so
Unable to load gtk_window_get_size from libgtk-3.so
Unable to load gtk_window_get_position from libgtk-3.so
Unable to load gtk_window_set_default_icon_list from libgtk-3.so
Unable to load gtk_window_set_default_size from libgtk-3.so
Unable to load gtk_window_set_keep_above from libgtk-3.so
Unable to load gtk_window_set_modal from libgtk-3.so
Unable to load gtk_window_set_position from libgtk-3.so
Unable to load gtk_window_set_title from libgtk-3.so
Unable to load gtk_window_set_transient_for from libgtk-3.so
Unable to load gtk_window_set_type_hint from libgtk-3.so
Unable to load gtk_window_stick from libgtk-3.so
Unable to load gtk_window_unfullscreen from libgtk-3.so
Unable to load gtk_widget_modify_bg from libgtk-3.so
Unable to load gtk_window_set_decorated from libgtk-3.so
Unable to load gtk_window_set_skip_taskbar_hint from libgtk-3.so
Unable to load gtk_window_set_skip_pager_hint from libgtk-3.so
Unable to load libgio-2.0.so
Unable to load g_file_get_path from libgio-2.0.so
Unable to load g_file_new_for_uri from libgio-2.0.so

When I try it on a simple dlopen example, it works, though:

void *cairo = dlopen("libcairo.so", RTLD_LAZY);
assert(dlerror() == NULL);

int (*cairo_version)(void);
*(void **) (&cairo_version) = dlsym(cairo, "cairo_version");
assert(dlerror() == NULL);

assert(cairo_version() > 0);

assert(dlclose(cairo) == 0);

Does Sublime do anything special with regards to dynamic loading?

Relevant NixOS issue

0 Likes

#2

I failed to realize that LD_PRELOADed libraries rely on their own DT_RUNPATH entries, rather than using the one from Sublime.

0 Likes