1 |
On 6/10/16 4:45 AM, Lei Zhang wrote: |
2 |
> Hi, |
3 |
> |
4 |
> I found this file on my musl based system built by GRS: |
5 |
> $ ls /usr/lib/gcc/x86_64-gentoo-linux-musl/4.9.3 | grep crtbegin |
6 |
> crtbegin.o |
7 |
> crtbeginP.o |
8 |
> crtbeginS.o |
9 |
> crtbeginT.o |
10 |
> |
11 |
> while on my host: |
12 |
> $ ls /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3 | grep crtbegin |
13 |
> crtbegin.o |
14 |
> crtbeginS.o |
15 |
> crtbeginT.o |
16 |
> |
17 |
> What is crtbeginP.o on the former system? I found very little info of |
18 |
> it on the internet. |
19 |
> |
20 |
> Also I'm trying to replace GCC's crtbegin/end with those from NetBSD. |
21 |
> But NetBSD doesn't offer the *S or *T variants, which are used by |
22 |
> "-static" and "-shared" options. What's special about them? Are they |
23 |
> just compiled out of the same source with different flags? |
24 |
> |
25 |
> Any inputs are appreciated :) |
26 |
> |
27 |
> Lei |
28 |
> |
29 |
|
30 |
those are the end files and they are used during linking. you can see |
31 |
them in use if you create a little test program and build it using |
32 |
|
33 |
gcc -v -o test test.c |
34 |
|
35 |
the last line of the verbose output looks something like the following |
36 |
on a glibc system: |
37 |
|
38 |
/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/collect2 -plugin |
39 |
/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/liblto_plugin.so |
40 |
-plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/lto-wrapper |
41 |
-plugin-opt=-fresolution=/tmp/cchAQ9r3.res |
42 |
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s |
43 |
-plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc |
44 |
-plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -m elf_x86_64 |
45 |
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -o test |
46 |
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/Scrt1.o |
47 |
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/crti.o |
48 |
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbeginS.o |
49 |
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3 |
50 |
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64 |
51 |
-L/lib/../lib64 -L/usr/lib/../lib64 |
52 |
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/lib |
53 |
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../.. /tmp/ccD0QtZd.o -lgcc |
54 |
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s |
55 |
--no-as-needed /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtendS.o |
56 |
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/crtn.o |
57 |
|
58 |
|
59 |
sifting through the output you see Scrt1.o crti.o crtbeginS.o ... |
60 |
crtendS.o crtn.o. the end files deployed will depend on whether you are |
61 |
doing pie and/or static and possibly other factors. i don't know that |
62 |
there is a standard meaning to the P, S or T. i remember when zorry and |
63 |
I work on this for the hardened compiler, we chose T for hardened. you |
64 |
can see the rules for deploying these files by looking at the gcc specs |
65 |
using `gcc -dumpspecs` |
66 |
|
67 |
so i recommend you play with different gcc compiler profiles using |
68 |
gcc-config on the musl based system you built with GRS, and look at the |
69 |
collect2 line to see which end files are deployed with each setting. |
70 |
then i recommend trying to read the gcc spec file for each of the |
71 |
compiler profiles. then if you know some assembly, look at the code for |
72 |
those end files which you can find in the musl source tree. that'll |
73 |
give you some idea what's going on there. |
74 |
|
75 |
its difficult stuff and since you couldn't find much on the internet, |
76 |
now's the time to get it there! document what you find in a systematic way. |
77 |
|
78 |
finally, i don't know clang. i suspect you'll have two issues going |
79 |
forward with that GRS system: 1) its hardened so how to do hardening |
80 |
with clang. does clang use gcc style specs? 2) how to get clang to |
81 |
play nice with musl |
82 |
|
83 |
btw i doubt strongly the netbsd end files would work. |
84 |
|
85 |
|
86 |
-- |
87 |
Anthony G. Basile, Ph.D. |
88 |
Gentoo Linux Developer [Hardened] |
89 |
E-Mail : blueness@g.o |
90 |
GnuPG FP : 1FED FAD9 D82C 52A5 3BAB DC79 9384 FA6E F52D 4BBA |
91 |
GnuPG ID : F52D4BBA |