On Wed, Jul 14, 2021 at 7:50 AM Sebastian Huber
<sebastian.hu...@embedded-brains.de> wrote:
>
> Hello,
>
> I noticed that the following static read-only object gets optimized away
> if optimization is enabled:
>
> /* Generate the pointer to the gcov_info_var in a dedicated section.  */
>
> static void
> build_gcov_info_var_registration (tree gcov_info_type)
> {
>    tree var = build_decl (BUILTINS_LOCATION,
>                          VAR_DECL, NULL_TREE,
>                          build_pointer_type (gcov_info_type));
>    TREE_STATIC (var) = 1;
>    TREE_READONLY (var) = 1;
>    char name_buf[32];
>    ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 2);
>    DECL_NAME (var) = get_identifier (name_buf);
>    get_section (profile_info_section, SECTION_UNNAMED, NULL);
>    set_decl_section_name (var, profile_info_section);
>    DECL_INITIAL (var) = build_fold_addr_expr (gcov_info_var);
>    varpool_node::finalize_decl (var);
> }
>
> I tried to add a TREE_USED (var) = 1, but this seems to have no effect.
> Could someone give me a hint what needs to be added so that this object
> is created? The object is placed in a linker set.

You can call mark_decl_referenced (var), TREE_USED is only used by frontends.

Richard.

>
> --
> embedded brains GmbH
> Herr Sebastian HUBER
> Dornierstr. 4
> 82178 Puchheim
> Germany
> email: sebastian.hu...@embedded-brains.de
> phone: +49-89-18 94 741 - 16
> fax:   +49-89-18 94 741 - 08
>
> Registergericht: Amtsgericht München
> Registernummer: HRB 157899
> Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
> Unsere Datenschutzerklärung finden Sie hier:
> https://embedded-brains.de/datenschutzerklaerung/

Reply via email to