D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19551 - corrupt ELF library when using pragma(crt_constructor)
Summary: corrupt ELF library when using pragma(crt_constructor)
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 critical
Assignee: No Owner
URL:
Keywords: backend
Depends on:
Blocks:
 
Reported: 2019-01-05 12:56 UTC by Rainer Schuetze
Modified: 2022-05-18 06:47 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2019-01-05 12:56:37 UTC
building these 2 files to a library:

//////////////////////////////////
module lib18456;
__gshared int initVar;

pragma(crt_constructor)
extern(C) void mir_cpuid_crt_init()
{
    initVar = 42;
}

/////////////////////////////////
module test18456b;

class ManualGC {
    void enable() {}
    void disable() {}
}

with "dmd -m64 -oftest.a -lib test18456b.d test18456.d"

produces a corrupt library that when linked with

/////////////////////////////////
import lib18456;

void main()
{
    assert(initVar == 42);
}

via via "dmd -m64 test18456.d test.a" produces:

/usr/bin/ld: error: test.a(lib18456.o): size of section .ctors is not multiple of address size
/usr/bin/ld: final link failed: Bad value

As the root corruption is not limited to use of pragma(crt_constructor), but just goes unnoticed otherwise, I've raised severity to "critical".
Comment 1 mhh 2022-05-18 02:40:03 UTC
I can't reproduce this
Comment 2 Rainer Schuetze 2022-05-18 06:47:44 UTC
I cannot reproduce it anymore, too. Might have been some intermediate version.