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

how create a shared library? #4

Closed
bioinfornatics opened this issue Aug 17, 2011 · 6 comments
Closed

how create a shared library? #4

bioinfornatics opened this issue Aug 17, 2011 · 6 comments

Comments

@bioinfornatics
Copy link
Contributor

1/ build project with pic

$ ldc2 -g -O3 -op -release -c -relocation-model=pic localization.d -of localization.o
localization.s-iWqEVS: Assembler messages:
localization.s-iWqEVS:105: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:107: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:108: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:129: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:131: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:132: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:147: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:149: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:150: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:168: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:170: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:171: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:452: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:454: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:455: Warning: stand-alone `data16' prefix

They are some warning but no error (i do not know whet is the problem with)

2/ create a shared library

$ ld -o localization.so -L/lib64/ -llphobos2 -lm -lpthread -ldl -lrt -ldruntime-ldc localization.o  -soname=localization.s
ld: warning: cannot find entry symbol _start; defaulting to 0000000000403140
/usr/lib64/liblphobos2.so: undefined reference to `__data_start'
/usr/lib64/liblphobos2.so: undefined reference to `_Dmain'

In which lib are define these thing?

2/ create a static lib is easy

$ ar rcs localization.o localization.a

thanks

@bioinfornatics
Copy link
Contributor Author

with gcc it works:

$ gcc  -Dlphobos2_EXPORTS -DDMDV2 -DIN_LLVM -D_DH -DOPAQUE_VTBLS -DPOSIX -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic  -fPIC -shared *.o -o liblocalization.so

with llvm-ld

llvm-ld -o localization.so -L/usr/lib64/ -llphobos2 -lm -ldl -lrt localization.o  -soname=localization.so

llvm-ar exist too never used

@bitraft
Copy link

bitraft commented Aug 27, 2011

Does this need druntime & rc lib building with PIC ?

@bioinfornatics
Copy link
Contributor Author

you can try it is the better thing :-) .
What you want to do?

@bioinfornatics
Copy link
Contributor Author

if is a lib you need use flag: -link-as-library

@bioinfornatics
Copy link
Contributor Author

just for update this topic, for generate a shared lib with llvm-ld they are several step:
In first generate llvm bytecode with --output-bc flag

$ ldc2 --output-bc --output-o  -op -release -c -relocation-model=pic  -od=../build *.d

llvm bytecode finish with .bc and are in ../build directory

$ cd ../build

Merge llvm bytecode together in one

$ lvm-ld -link-as-library -o libDparser.bc -L/usr/local/lib64/ -L/usr/lib64 -ldruntime-ldc -llphobos2 -lm -ldl -lrt -soname=Dparser *.bc

run llc

$ llc -relocation-model=pic libDparser.bc

End the process by build shared lib

$ gcc -shared libDparser.s -o libDparser.so

@dnadlinger
Copy link
Member

LDC now has a -shared flag.

kinke pushed a commit that referenced this issue Nov 25, 2022
The test checks the stack frame of `_Dmain` is in the backtrace, however if unused locals are optimised out and`test` is inlined into `main` 
```d
void test()
{
    int innerLocal = 20;
    throw new Exception("foo");
}
void main(string[] args)
{
    string myLocal = "bar";
    test();
}
```
then the point at which the untapped exception is thrown is at the start of D main - not somewhere in the middle of it - and so GDB prints 
```
...
#4 D main (args=...)
```
rather than 
```
...
#4 0xSOMEADDRESS in D main (args=...)
```
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

3 participants