Re: Possible OS incompatibility with __attribute__ 'shared'
LIU Hao via Gcc-help <[email protected]> Mon, 22 Dec 2025 16:48:00 +0800
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
在 2025-12-22 06:47, [email protected] 写道: > Thanks, but that does not answer the question. The compiled code runs on BOTH systems. The only difference is that the method described does not work on Windows 7, whether the resulting executables are recompiled there or not. If it had never worked at all, I'd consider the choice of compiler version as relevant. I don't have Windows 7 by hand, but I have tried it on Windows 11 and it works as expected. To check whether the attribute is applied correctly, you may invoke `objdump -h` and look for the `SHARED` flag: $ objdump -h value.dll value.dll: file format pei-x86-64 Sections: Idx Name Size VMA LMA File off Algn 0 .text 00001430 0000000209e11000 0000000209e11000 00000600 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .data 00000048 0000000209e13000 0000000209e13000 00001c00 2**2 CONTENTS, ALLOC, LOAD, DATA 2 share 00000004 0000000209e14000 0000000209e14000 00001e00 2**2 CONTENTS, ALLOC, LOAD, DATA, SHARED ... The section is only shared by processes that load the same DLL file. It is not shared by processes that load different copies of the DLL. > The question is not about the versions of GCC. It's about the compatibility for the method as described, given that it works in one Windows OS but not the other. If this puts it beyond the scope of advice on GCC, how about some other simple way to share a single variable between processes using a hook DLL. I mention that because I'm trying to avopid making this an 'XY' problem (a phrase I see a lot on StackOverflow...) You can use named shared memory for that purpose, passing a hard-coded UUID as a name. There's a tutorial for it: https://learn.microsoft.com/en-us/windows/win32/dlls/using-shared-memory-in-a-dynamic-link-library -- Best regards, LIU Hao
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEYmSQWY4DEzq4FUs4hfveZl3ogBsFAmlJBcAFAwAAAAAACgkQhfveZl3ogBsd BQ//dRaXPiwtnXpq6nfODzSIc+qC/LdZzi0ORDhf0jbpWm47BwN8L+W/1jXwi9tq5SbTZgLYup7T a6x14z+MrhKpsnpzsFqkc1DD5m2Q6M4NK6Htr7mPRqMo2B/HnpNvHHzeKlJ/zC7Jbts15eRfFfz/ /ggJddl1neErfitEbbkmTKi8ARXlqFHZvLyQSm4YIysMw3/Z8JUMwx7hxfMKsM/imsxuXgQeW42M E3t2VpiON/QZsSbCA92kOy477qawLBAACPZsL+haVahBwS9CHmboXT4Esi+O9mODjqHDPnJMffSG P4AyL3peucpvQq4QFFDGQEdmDj5ZOWIggArdvNzRj1SuREpXlGUjJU0W3Y27uOB4BT6qw9ti8HLZ V4WCXZCn1jnW1fF9kjS1b5MWdWK25CTN/vDzjE57jkWPdpZWfPuEn6f5WX/hlXHUw/VwmxxgMBLy 6AOjqSoGpsyoD7yBGMVBI5U2Sdb/exnIpO+veJ36zGLUu6R2zaJNMkPhpAgS+W6Nm+sSYLC3avES xDTUyte2UnsOmv1BSsv56Hm2hODeW22A8DHTlYgFLFCGPuOxSnp04ZHFgihmrv15A+pQKmjJNkhC tjcLTNDRtNxxhloLShNpvE2rOfm716VzblQ4F5w7C/Rjje/f8Km9o/bKFczth5rT6v8sEvKRhYMO FPs= =C5+L -----END PGP SIGNATURE-----