{"id":20606019,"url":"https://github.com/martinitus/rust-library-linkage-experiments","last_synced_at":"2025-03-06T17:16:13.873Z","repository":{"id":197283864,"uuid":"698335844","full_name":"martinitus/rust-library-linkage-experiments","owner":"martinitus","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-29T18:27:07.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T02:35:18.539Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martinitus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-29T17:22:34.000Z","updated_at":"2023-09-29T17:23:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"c3403170-2041-4f7f-969a-bd164f5cde10","html_url":"https://github.com/martinitus/rust-library-linkage-experiments","commit_stats":null,"previous_names":["martinitus/rust-library-linkage-experiments"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinitus%2Frust-library-linkage-experiments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinitus%2Frust-library-linkage-experiments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinitus%2Frust-library-linkage-experiments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinitus%2Frust-library-linkage-experiments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinitus","download_url":"https://codeload.github.com/martinitus/rust-library-linkage-experiments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242250926,"owners_count":20096897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T09:32:07.459Z","updated_at":"2025-03-06T17:16:13.856Z","avatar_url":"https://github.com/martinitus.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How does linkage and dynamic loading of libraries effect static global variables?\n\nThis repo contains 3 libraries and one executable linking to those libraries.\nThe dependency graph looks as follows:\n\n```\n      ┌─────┐\n      │     │\n   ┌──┤  A  ├─┐\n   │  │     │ │\n   │  └─┬───┘ │\n   │    │     │\n┌──▼──┐ │ ┌───▼─┐\n│     │ │ │     │\n│  B  │ │ │  C  │\n│     │ │ │     │\n└┬────┘ │ └───┬─┘\n │      │     │\n │ ┌────▼───┐ │\n │ │        │ │\n └─►  exe   │◄┘\n   │        │\n   └────────┘\n```\n\nI.e.: \n- B links against A\n- C links against A\n- exe links against A\n- exe links against B\n- exe links against C\n\nLibrary A contains a static global variable and a minimal api to read and write its value.\nThis value will be changed and read from the executable direcltly via A, and indirectly via B or C.\nFurther, the executable loads B via libloading at runtime and changes the value in A via the dynamically loaded B.\n\nThe output on my machine (windows) is as follows:\n\n```\nexe sees: 0\nb sees: 0\nc sees: 0\n================\nsetting to 1 directly via a    \nexe sees: 1\nb sees: 1\nc sees: 1\n================\nsetting to 2 via b\nexe sees: 2\nb sees: 2\nc sees: 2\n=======DYNAMIC LOADING=========\nb-dyn-loaded sees: 0\nsetting to 3via dyn-loaded-b   \nexe sees: 2\nb sees: 2\nb-dyn-loaded sees: 3\nc sees: 2\n```\n\n__This shows, that even with dynamic linking, the dynamically loaded A (via B) still has its own memory region for the \nstatic variable.__\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinitus%2Frust-library-linkage-experiments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinitus%2Frust-library-linkage-experiments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinitus%2Frust-library-linkage-experiments/lists"}