Changeset b192915a in mainline


Ignore:
Timestamp:
2024-05-29T18:11:25Z (8 weeks ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
c576800
Parents:
9b95b964
Message:

Add test case for public variable initialized with a relocated value

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/dltest/dltest.c

    r9b95b964 rb192915a  
    11/*
    2  * Copyright (c) 2016 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    571571#ifdef DLTEST_LINKED
    572572
     573/** Test if we can read the correct value of a public pointer variable.
     574 *
     575 * dl_public_ptr_var is initialized in libdltest to point to dl_public_var.
     576 * This is done using a relocation. The main program (unless compiled with
     577 * PIC or PIE) will contain a copy of dl_public_ptr_var. This needs
     578 * to be copied using a COPY relocation. The relocations in the main
     579 * program need to be processed after the relocations in the shared
     580 * libraries (so that we copy the correct value).
     581 */
     582static bool test_public_ptr_var(void)
     583{
     584        int *ptr;
     585
     586        printf("Read dl_public_ptr_var directly...\n");
     587        ptr = dl_public_ptr_var;
     588
     589        if (ptr != &dl_public_var) {
     590                printf("FAILED\n");
     591                return false;
     592        }
     593
     594        printf("Passed\n");
     595        return true;
     596}
     597
    573598/** Test directly calling function that returns a constant */
    574599static bool test_lnk_dl_get_constant(void)
     
    920945
    921946#ifndef STATIC_EXE
     947
    922948        if (!test_dlfcn_dl_get_private_fib_var())
    923949                return 1;
     
    9741000
    9751001        if (!test_lnk_read_public_uvar())
     1002                return 1;
     1003
     1004        if (!test_public_ptr_var())
    9761005                return 1;
    9771006
  • uspace/lib/dltest/dltest.c

    r9b95b964 rb192915a  
    11/*
    2  * Copyright (c) 2016 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4343/** Public initialized variable */
    4444int dl_public_var = dl_public_var_val;
     45/** Public variable initialized with the address of a symbol */
     46int *dl_public_ptr_var = &dl_public_var;
    4547/** Public uninitialized variable */
    4648int dl_public_uvar;
  • uspace/lib/dltest/libdltest.h

    r9b95b964 rb192915a  
    11/*
    2  * Copyright (c) 2016 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6767extern int dl_public_var;
    6868extern int dl_public_uvar;
     69extern int *dl_public_ptr_var;
    6970extern fibril_local int dl_public_fib_var;
    7071extern fibril_local int dl_public_fib_uvar;
Note: See TracChangeset for help on using the changeset viewer.