Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkonce-templates bugs #4579

Open
calvin2021y opened this issue Feb 9, 2024 · 2 comments
Open

linkonce-templates bugs #4579

calvin2021y opened this issue Feb 9, 2024 · 2 comments

Comments

@calvin2021y
Copy link

linkonce-templates can not use with betterC code

@calvin2021y
Copy link
Author

1.37.0-beta1

ldmd2 -betterC test1.d -I. -linkonce-templates 

test1.d

import test2;

@nogc nothrow:

enum ARR = idupArray!();

extern(C) int main(int argc, char** argv){
	return 0;
}

test2.d

module test2;

struct Column {
    @nogc nothrow:
	int id;
}

auto idupArray()(){
	if (!__ctfe)
			return null;
	Column[2] _arr;
	return _arr[0..1].idup;
}
import/core/internal/array/duplication.d(39): Error: appending to array in `res ~= cast(immutable(Column))e` requires the GC which is not available with -betterC

remove linkonce-templates fix the problem.

@kinke
Copy link
Member

kinke commented Feb 9, 2024

Thx for the nice test case. This ultimately boils down to __ctfe being a runtime-constant, so the .idup call still ends up being codegen'd at the IR level, and then drags in further templates, most notably

if (__ctfe)
return _dupCtfe!(T, U)(a);
version (D_BetterC)
{
return _dupCtfe!(T, U)(a);
}

-linkonce-templates per definition emits all instantiated symbols referenced at the IR level, so a _dupCtfe instantiation too, which is only forward-declared without -linkonce-templates. In fact, without linker culling getting rid of unreferenced symbols:

ldc2 test1.d -betterC -disable-linker-strip-dead
ld: error: undefined symbol: _D4core8internal5array11duplication__T8_dupCtfeTS5test26ColumnTySQqQmZQBgFNaNbNiNfMAQBkZAyQBa
>>> referenced by test1.d
>>>               test1.o:(_D4core8internal5array11duplication__T4_dupTS5test26ColumnTySQqQmZQBcFNaNbNiNeMAQBkZAyQBa)
collect2: error: ld returned 1 exit status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants