ELF 部分未链接
ELF section not being linked
我 运行 在使用 GNU 链接器时遇到了一些问题。
简而言之,我有一个具有 .yksir_ykpack
ELF 部分的对象,它与一个具有 .yksir_yktrace
ELF 部分的对象链接。期望的结果是包含这两个部分的二进制文件。
这是包含 .yksir_ykpack
部分的对象:
readelf --section-headers /home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib 2>/dev/null
...
File: /home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib(ykpack-2a9122d94a2f837e.4kxe4998mamwcrkf.rcgu.o)
There are 6 section headers, starting at offset 0xc25f8:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .strtab STRTAB 0000000000000000 000c2580
0000000000000074 0000000000000000 0 0 1
[ 2] .text PROGBITS 0000000000000000 00000040
0000000000000000 0000000000000000 AX 0 0 4
[ 3] .yksir_ykpack PROGBITS 0000000000000000 00000040
00000000000c24f5 0000000000000000 0 0 16
[ 4] .note.GNU-stack PROGBITS 0000000000000000 000c2535
0000000000000000 0000000000000000 0 0 1
[ 5] .symtab SYMTAB 0000000000000000 000c2538
0000000000000048 0000000000000018 1 2 8
...
请注意,此对象是 Rust rlib,但它与 ELF 兼容。
另请注意,rlib 中还有其他 "sub-files"。我已经删除了它们。
正在链接的另一个对象(包含 .yksir_yktrace
)是一个常规 .o
文件。
并且由于默认链接描述文件无法识别我的节名称,因此我使用了节指令(内联 asm)。例如,对于 .yksir_ykpack
:
.section .yksir_ykpack, "", @progbits
现在这是我们的链接器命令行(抱歉它很长——很难在我的设置中做一个最小的例子):
cc \
-Wl,--as-needed \
-Wl,-z,noexecstack \
-m64 \
-L \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.10c166lfq64r2e3y.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.10qcnu2sbqobows0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.115niq53kx6tizom.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.120g6826u8fiklab.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.14rek8asgh23tnza.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.154hfu34te2ge40t.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.177trhwt854ryxrc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.18scvl9vj2f5b06v.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.18vw9lln0d5b3qrw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1b3h401yq8qa8ur5.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1b77e65v6f58yuv6.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1bx0tifep7a0rrg2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1f45w8utte9cb7vq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1gu52jpfp6kyy8ga.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1gxs1zbjd9l1x29m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1jidej0kgblhzsyd.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1kxugzjco2szwc38.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1lgrutz0tyx7absl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1ozmuob6f299nm7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1q2fa8g6b78o6dlx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1rlyknl6qs9nwcax.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1xi7nbo1lotv9jbw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.241a14yvztsg3uho.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.263wkarma1f4il5c.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.26z1aszmxuxamrl6.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2853vbh8zenhwv7w.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.28bq65c862o6lbw3.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2928kri5ycvnjicw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.293in29h8y2p3l2b.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2bhdn9m34dljrb32.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2c3zsda0wuw2rgnr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2c7gsrv4f7hrohm9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2crlph00pparx8rl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2d9e1vcwdgfeqahl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2dshiej7wzf5qhqc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2f8ravnggrepx4x9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2h6d7quzn2azwinl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2i9tj89psdv0p93c.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2ibi7q757d8gjivn.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2o8kwjdjgy2ybl41.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2oiqp6v3amvs5ntu.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2q1okbobeouigo3x.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2qfanjg39058djk4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2r2b4hs5fzkuh2xg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2r63byzwj3tomouq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2solqp985j0ij1iv.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2tukccybgj9vycj9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2ufh1wltjgi0ncw8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2v16mhbnkzo2h1j1.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2vpbdcbcpuaozllz.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2w6ewmxetdc306hu.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2wmzmwzopnst0oks.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2x6tg5n30lb0h4dm.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2y1u4ztvloojzu1e.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.32ako2nv80o7xnx9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.336kexx0suto8yk0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.34a312torkwd02am.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.38eqcg27n3vxgdmg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3c45tbmi2ikdru55.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3csuiad3mvn7wgqc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3d1afrosx210ksv8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3fm3cboeuara00yc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3gq2u8x551t2ef0u.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3itxhruj3tgegtyr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3k1x60obvhk78c0f.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3k2mv967ff5wbde9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3keaisjesqpgzid7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3knbirxkrhjnqc0j.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3lka49k5uun01x61.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3m1g3a2t7sziz3k8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3mbasooz3zq9lq2j.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3nfs7qwaz8pe36zr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3nnnuv59023znw62.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3ptew4t1q7mvc8z2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3qdehdp4kxtbq0tj.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3r7sp7knkxz5a9u2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3rnnuvaazxtmknct.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3rw5uarkaib7yafm.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3vsqsa5e8ys24frq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3wddp6f4tv68zbr3.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3yyfhdodvs54rvbs.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3zj0neynl1tg27y0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3zx5ut953nbpjm4h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.42g1k7sztcmhf5ak.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.46bo2vabr45h9mqv.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.46dmw1z0esu1hxri.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.479eiwn05j7vuk1p.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.47g9z8o12t0bz84h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.49o7bkfhu7tpp5ra.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4ab0cs1z37jlq52s.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4do73rnjg7fn2sou.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4f6peemwtbhuiqw4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4h2ljwnazsotxzgx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4j1d9zei95ciav3u.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4l4m07sfgf7zynqq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4lhkgbdz114036lo.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4lufiuj41yjsxxxy.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4njp70315f2wj26b.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4nxht76y2opj1mic.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4q23mole4mu9mt24.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4qd7hpf2syf2o2pp.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4wiu8i53hl4c96yo.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5143dlty43nxmbim.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.57dfjw10traxw3ae.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5ckz2fx2s5apni0f.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5dy4mq6l10uhilba.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5eapic3g6plq22h8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5eba7m25m1l02h9m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5gudrx0yblx2aj77.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5krt6jfk0979emg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.62xy9gq4fuhf36h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.7nla6xrkcjgwurc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.8jk62bksvzymbp5.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.ggonqqon6gxi2af.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.gjhkwkf95up18pw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.hxqc3dcbdk1faag.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.j2yhsf7842yw3sb.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jey67dcpnxuoywx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jhvojsq8gkuti7k.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jybymzk00d3e5t7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.kqmbtygjxlnx47m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.ndroblzkpdcjzo1.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.o3bxbvma8t5xkne.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.r1w6eadga16ihy4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.s6ldoaew31npivj.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.tmt3fv8lu8oua6k.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.v51zeo4f699m0ti.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.w55t39wk5qjg2bc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.xp7r6sx9ppyf9t0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.y8lfemb87vtfeob.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.zwjbkly56hl6j7y.rcgu.o \
-o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3qhbgyy4j5mr4hcm.rcgu.o \
-pie \
-Wl,-zrelro \
-Wl,-znow \
-nodefaultlibs \
-L \
/home/vext01/research/yk/target/debug/deps \
-L \
/home/vext01/research/yk/target/debug/build/hwtracer-928324455c3b5b0d/out \
-L \
/home/vext01/.cargo/git/checkouts/hwtracer-07feaf5fa95de145/fdce391/c_deps/inst/lib \
-L \
/home/vext01/research/yk/target/debug/build/hwtracer-928324455c3b5b0d/out \
-L \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib \
-Wl,-Bstatic \
/home/vext01/research/yk/target/debug/deps/libmemmap-5f23cb5259f61858.rlib \
/home/vext01/research/yk/target/debug/deps/libgimli-d46f6b1d6250e62c.rlib \
/home/vext01/research/yk/target/debug/deps/libindexmap-a7445e071182095b.rlib \
/home/vext01/research/yk/target/debug/deps/libarrayvec-4d4c4abac05eec7a.rlib \
/home/vext01/research/yk/target/debug/deps/libnodrop-3da1b04b3cad85a5.rlib \
/home/vext01/research/yk/target/debug/deps/libstable_deref_trait-7630eaff18b8ab57.rlib \
/home/vext01/research/yk/target/debug/deps/libelf-97ced5ab8064f12b.rlib \
/home/vext01/research/yk/target/debug/deps/libbyteorder-a1ca60651d3abac3.rlib \
/home/vext01/research/yk/target/debug/deps/libphdrs-b9f0bd244ef345ca.rlib \
/home/vext01/research/yk/target/debug/deps/libobject-78dffdc0007e71b6.rlib \
/home/vext01/research/yk/target/debug/deps/libparity_wasm-6e118c1ea26bb0ca.rlib \
/home/vext01/research/yk/target/debug/deps/libflate2-a0dbcb32ab5b92bb.rlib \
/home/vext01/research/yk/target/debug/deps/libminiz_oxide-feee87a1e827d34e.rlib \
/home/vext01/research/yk/target/debug/deps/libadler32-df5c7e6116a31c83.rlib \
/home/vext01/research/yk/target/debug/deps/libcrc32fast-e74dc8ce28b7f377.rlib \
/home/vext01/research/yk/target/debug/deps/libgoblin-31c3e1931784d72b.rlib \
/home/vext01/research/yk/target/debug/deps/liblog-6bd6a1a9417c9b44.rlib \
/home/vext01/research/yk/target/debug/deps/libplain-815d5b934f3c458c.rlib \
/home/vext01/research/yk/target/debug/deps/libscroll-57c304c9c9aa4f19.rlib \
/home/vext01/research/yk/target/debug/deps/libuuid-d9fa09a0ac505087.rlib \
/home/vext01/research/yk/target/debug/deps/libtarget_lexicon-bd6c9c95040de744.rlib \
/home/vext01/research/yk/target/debug/deps/libfailure-883b6313101c519f.rlib \
/home/vext01/research/yk/target/debug/deps/libhwtracer-4a7fcfc6cdb25d08.rlib \
/home/vext01/research/yk/target/debug/deps/libtempfile-f73c3fca6b62eb80.rlib \
/home/vext01/research/yk/target/debug/deps/librand-df0ca11adb03b8e3.rlib \
/home/vext01/research/yk/target/debug/deps/librand_chacha-276a59e9166a9193.rlib \
/home/vext01/research/yk/target/debug/deps/libc2_chacha-170e0ce215266f6e.rlib \
/home/vext01/research/yk/target/debug/deps/libppv_lite86-8dd4ff65271756be.rlib \
/home/vext01/research/yk/target/debug/deps/librand_core-4c118f0513457ff6.rlib \
/home/vext01/research/yk/target/debug/deps/libgetrandom-a724117bf2304247.rlib \
/home/vext01/research/yk/target/debug/deps/libremove_dir_all-635dd99a7c406912.rlib \
/home/vext01/research/yk/target/debug/deps/libcfg_if-6454a07998dfdf77.rlib \
/home/vext01/research/yk/target/debug/deps/libtime-de6100a3b17d5591.rlib \
/home/vext01/research/yk/target/debug/deps/liblibc-7376e8de49ab6c4d.rlib \
/home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib \
/home/vext01/research/yk/target/debug/deps/librmp_serde-337cde3a4d7cf067.rlib \
/home/vext01/research/yk/target/debug/deps/libserde-af0b54eec19c1f21.rlib \
/home/vext01/research/yk/target/debug/deps/librmp-3e2e145986c5b5a2.rlib \
/home/vext01/research/yk/target/debug/deps/libnum_traits-e132ced7a5978735.rlib \
/home/vext01/research/yk/target/debug/deps/libbyteorder-06c02cccfe57c005.rlib \
/home/vext01/research/yk/target/debug/deps/libfallible_iterator-72f65c2f6c00d6f7.rlib \
/home/vext01/research/yk/target/debug/deps/liblazy_static-40baa21fb02fe58c.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-fa7c5db992c603ae.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libterm-677b7a33a112844b.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-3823ca10bcc34fef.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-b085949ade5be118.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-937f89c7b4331592.rlib \
-Wl,--start-group \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d5a0f5d9c2ecbc13.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-6214af4642f83019.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-d853b38ef82d1b80.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-b5c8492ce140f2f4.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-4f884e18d6db8201.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-55bf2675880f6c0f.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e80dead6761c88af.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-a0079eacbe814aa8.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-eaebc19628616584.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-041597c76bfe99c8.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4f9776276b6dc54c.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-f0c8c9c0de0535e4.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-cf28f55e983f3931.rlib \
-Wl,--end-group \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-f4dd3b487c184fe0.rlib \
-Wl,-Bdynamic \
-lipt \
-lutil \
-lutil \
-ldl \
-lrt \
-lpthread \
-lgcc_s \
-lc \
-lm \
-lrt \
-lpthread \
-lutil \
-lutil \
-Wl,--no-gc-sections \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2qajgdgxxha7pskm.rcgu.o
这成功了,但是当我们检查生成的二进制文件时,.yksir_ykpack
丢失了:
$ readelf --section-headers /home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 2>/dev/null | grep 'yksir_ykpack'
$
.yksir_yktrace
部分 是 在二进制文件中:
$ readelf --section-headers /home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 2>/dev/null | grep 'yksir_yktrace'
...
[31] .yksir_yktrace PROGBITS 0000000000000000 009ba0e0
0000000000078ed3 0000000000000000 0 0 16
有人知道这是为什么吗? .yksir_ykpack
去哪儿了?
我试过删除 -Wl,--as-needed
并向上移动 -Wl,--no-gc-sections
。不开心。
谢谢!
我想通了。
这里的关键细节是 Rust .rlib
文件是静态库。与 .o
目标文件不同,当 linking 静态库(通常是 .a
文件)时,linker 使用解析步骤仅引入尚未定义的符号和没有别的。
这可以通过这个最小的例子看出:
all: main_a main_o main_a_whole dump
# Generate text files to use as the contents of the sections.
my_section1.raw:
echo "mydata1" > $@
my_section2.raw:
echo "mydata2" > $@
# Generate object files for the sections.
my_section1.o: my_section1.raw
objcopy --input-target binary \
--output-target=elf64-x86-64 \
--binary-architecture i386:x86-64 \
--rename-section .data=.my_section1 \
my_section1.raw $@
my_section2.o: my_section2.raw
objcopy --input-target binary \
--output-target=elf64-x86-64 \
--binary-architecture i386:x86-64 \
--rename-section .data=.my_section2 \
my_section2.raw $@
# And for section1 only, we will make a static lib.
my_section1.a: my_section1.o
ar rcs $@ my_section1.o
# A "main" stub to link our objects to.
main.c:
echo "void main(void) {}" > main.c
# Now make some binaries using varying linkage configurations.
# main_o is made from the object files.
main_o: main.o my_section1.a my_section2.o
${CC} -o $@ my_section1.o my_section2.o main.o
# main_a uses the static lib for section1 and the object file for section2.
main_a: main.o my_section1.a my_section2.o
${CC} -o $@ my_section1.a my_section2.o main.o
# main_a_whole is the same as main_a, but uses --whole-archive when linking section1.
main_a_whole: main.o my_section1.a my_section2.o
${CC} -o $@ -Wl,--whole-archive my_section1.a -Wl,--no-whole-archive my_section2.o main.o
# Print the sections of interest from the resulting binaries.
dump:
@echo "\n>>> main_o sections"
objdump -h main_o | grep my_section
@echo "\n>>> main_a sections"
objdump -h main_a | grep my_section
@echo "\n>>> main_a_whole sections"
objdump -h main_a_whole | grep my_section
clean:
rm -f *.o *.a main_a main_o main_a_whole *.raw main.c
当运行时,我们得到:
>>> main_o sections
objdump -h main_o | grep my_section
23 .my_section1 00000008 0000000000004028 0000000000004028 00003028 2**0
24 .my_section2 00000008 0000000000004030 0000000000004030 00003030 2**0
>>> main_a sections
objdump -h main_a | grep my_section
23 .my_section2 00000008 0000000000004028 0000000000004028 00003028 2**0
>>> main_a_whole sections
objdump -h main_a_whole | grep my_section
23 .my_section1 00000008 0000000000004028 0000000000004028 00003028 2**0
24 .my_section2 00000008 0000000000004030 0000000000004030 00003030 2**0
注意使用 --whole-archive
强制加载整个静态库。这可能是不可取的,因为您可能希望完全 link 只有一个部分,这不能直接完成 AFAICS。在这种情况下,您可以使用 ar
或 objcopy
和 link 来提取部分。
我 运行 在使用 GNU 链接器时遇到了一些问题。
简而言之,我有一个具有 .yksir_ykpack
ELF 部分的对象,它与一个具有 .yksir_yktrace
ELF 部分的对象链接。期望的结果是包含这两个部分的二进制文件。
这是包含 .yksir_ykpack
部分的对象:
readelf --section-headers /home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib 2>/dev/null
...
File: /home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib(ykpack-2a9122d94a2f837e.4kxe4998mamwcrkf.rcgu.o)
There are 6 section headers, starting at offset 0xc25f8:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .strtab STRTAB 0000000000000000 000c2580
0000000000000074 0000000000000000 0 0 1
[ 2] .text PROGBITS 0000000000000000 00000040
0000000000000000 0000000000000000 AX 0 0 4
[ 3] .yksir_ykpack PROGBITS 0000000000000000 00000040
00000000000c24f5 0000000000000000 0 0 16
[ 4] .note.GNU-stack PROGBITS 0000000000000000 000c2535
0000000000000000 0000000000000000 0 0 1
[ 5] .symtab SYMTAB 0000000000000000 000c2538
0000000000000048 0000000000000018 1 2 8
...
请注意,此对象是 Rust rlib,但它与 ELF 兼容。
另请注意,rlib 中还有其他 "sub-files"。我已经删除了它们。
正在链接的另一个对象(包含 .yksir_yktrace
)是一个常规 .o
文件。
并且由于默认链接描述文件无法识别我的节名称,因此我使用了节指令(内联 asm)。例如,对于 .yksir_ykpack
:
.section .yksir_ykpack, "", @progbits
现在这是我们的链接器命令行(抱歉它很长——很难在我的设置中做一个最小的例子):
cc \
-Wl,--as-needed \
-Wl,-z,noexecstack \
-m64 \
-L \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.10c166lfq64r2e3y.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.10qcnu2sbqobows0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.115niq53kx6tizom.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.120g6826u8fiklab.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.14rek8asgh23tnza.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.154hfu34te2ge40t.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.177trhwt854ryxrc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.18scvl9vj2f5b06v.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.18vw9lln0d5b3qrw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1b3h401yq8qa8ur5.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1b77e65v6f58yuv6.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1bx0tifep7a0rrg2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1f45w8utte9cb7vq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1gu52jpfp6kyy8ga.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1gxs1zbjd9l1x29m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1jidej0kgblhzsyd.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1kxugzjco2szwc38.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1lgrutz0tyx7absl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1ozmuob6f299nm7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1q2fa8g6b78o6dlx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1rlyknl6qs9nwcax.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1xi7nbo1lotv9jbw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.241a14yvztsg3uho.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.263wkarma1f4il5c.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.26z1aszmxuxamrl6.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2853vbh8zenhwv7w.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.28bq65c862o6lbw3.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2928kri5ycvnjicw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.293in29h8y2p3l2b.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2bhdn9m34dljrb32.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2c3zsda0wuw2rgnr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2c7gsrv4f7hrohm9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2crlph00pparx8rl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2d9e1vcwdgfeqahl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2dshiej7wzf5qhqc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2f8ravnggrepx4x9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2h6d7quzn2azwinl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2i9tj89psdv0p93c.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2ibi7q757d8gjivn.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2o8kwjdjgy2ybl41.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2oiqp6v3amvs5ntu.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2q1okbobeouigo3x.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2qfanjg39058djk4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2r2b4hs5fzkuh2xg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2r63byzwj3tomouq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2solqp985j0ij1iv.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2tukccybgj9vycj9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2ufh1wltjgi0ncw8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2v16mhbnkzo2h1j1.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2vpbdcbcpuaozllz.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2w6ewmxetdc306hu.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2wmzmwzopnst0oks.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2x6tg5n30lb0h4dm.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2y1u4ztvloojzu1e.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.32ako2nv80o7xnx9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.336kexx0suto8yk0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.34a312torkwd02am.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.38eqcg27n3vxgdmg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3c45tbmi2ikdru55.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3csuiad3mvn7wgqc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3d1afrosx210ksv8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3fm3cboeuara00yc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3gq2u8x551t2ef0u.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3itxhruj3tgegtyr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3k1x60obvhk78c0f.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3k2mv967ff5wbde9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3keaisjesqpgzid7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3knbirxkrhjnqc0j.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3lka49k5uun01x61.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3m1g3a2t7sziz3k8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3mbasooz3zq9lq2j.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3nfs7qwaz8pe36zr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3nnnuv59023znw62.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3ptew4t1q7mvc8z2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3qdehdp4kxtbq0tj.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3r7sp7knkxz5a9u2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3rnnuvaazxtmknct.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3rw5uarkaib7yafm.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3vsqsa5e8ys24frq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3wddp6f4tv68zbr3.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3yyfhdodvs54rvbs.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3zj0neynl1tg27y0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3zx5ut953nbpjm4h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.42g1k7sztcmhf5ak.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.46bo2vabr45h9mqv.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.46dmw1z0esu1hxri.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.479eiwn05j7vuk1p.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.47g9z8o12t0bz84h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.49o7bkfhu7tpp5ra.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4ab0cs1z37jlq52s.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4do73rnjg7fn2sou.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4f6peemwtbhuiqw4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4h2ljwnazsotxzgx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4j1d9zei95ciav3u.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4l4m07sfgf7zynqq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4lhkgbdz114036lo.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4lufiuj41yjsxxxy.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4njp70315f2wj26b.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4nxht76y2opj1mic.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4q23mole4mu9mt24.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4qd7hpf2syf2o2pp.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4wiu8i53hl4c96yo.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5143dlty43nxmbim.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.57dfjw10traxw3ae.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5ckz2fx2s5apni0f.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5dy4mq6l10uhilba.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5eapic3g6plq22h8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5eba7m25m1l02h9m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5gudrx0yblx2aj77.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5krt6jfk0979emg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.62xy9gq4fuhf36h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.7nla6xrkcjgwurc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.8jk62bksvzymbp5.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.ggonqqon6gxi2af.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.gjhkwkf95up18pw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.hxqc3dcbdk1faag.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.j2yhsf7842yw3sb.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jey67dcpnxuoywx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jhvojsq8gkuti7k.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jybymzk00d3e5t7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.kqmbtygjxlnx47m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.ndroblzkpdcjzo1.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.o3bxbvma8t5xkne.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.r1w6eadga16ihy4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.s6ldoaew31npivj.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.tmt3fv8lu8oua6k.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.v51zeo4f699m0ti.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.w55t39wk5qjg2bc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.xp7r6sx9ppyf9t0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.y8lfemb87vtfeob.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.zwjbkly56hl6j7y.rcgu.o \
-o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3qhbgyy4j5mr4hcm.rcgu.o \
-pie \
-Wl,-zrelro \
-Wl,-znow \
-nodefaultlibs \
-L \
/home/vext01/research/yk/target/debug/deps \
-L \
/home/vext01/research/yk/target/debug/build/hwtracer-928324455c3b5b0d/out \
-L \
/home/vext01/.cargo/git/checkouts/hwtracer-07feaf5fa95de145/fdce391/c_deps/inst/lib \
-L \
/home/vext01/research/yk/target/debug/build/hwtracer-928324455c3b5b0d/out \
-L \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib \
-Wl,-Bstatic \
/home/vext01/research/yk/target/debug/deps/libmemmap-5f23cb5259f61858.rlib \
/home/vext01/research/yk/target/debug/deps/libgimli-d46f6b1d6250e62c.rlib \
/home/vext01/research/yk/target/debug/deps/libindexmap-a7445e071182095b.rlib \
/home/vext01/research/yk/target/debug/deps/libarrayvec-4d4c4abac05eec7a.rlib \
/home/vext01/research/yk/target/debug/deps/libnodrop-3da1b04b3cad85a5.rlib \
/home/vext01/research/yk/target/debug/deps/libstable_deref_trait-7630eaff18b8ab57.rlib \
/home/vext01/research/yk/target/debug/deps/libelf-97ced5ab8064f12b.rlib \
/home/vext01/research/yk/target/debug/deps/libbyteorder-a1ca60651d3abac3.rlib \
/home/vext01/research/yk/target/debug/deps/libphdrs-b9f0bd244ef345ca.rlib \
/home/vext01/research/yk/target/debug/deps/libobject-78dffdc0007e71b6.rlib \
/home/vext01/research/yk/target/debug/deps/libparity_wasm-6e118c1ea26bb0ca.rlib \
/home/vext01/research/yk/target/debug/deps/libflate2-a0dbcb32ab5b92bb.rlib \
/home/vext01/research/yk/target/debug/deps/libminiz_oxide-feee87a1e827d34e.rlib \
/home/vext01/research/yk/target/debug/deps/libadler32-df5c7e6116a31c83.rlib \
/home/vext01/research/yk/target/debug/deps/libcrc32fast-e74dc8ce28b7f377.rlib \
/home/vext01/research/yk/target/debug/deps/libgoblin-31c3e1931784d72b.rlib \
/home/vext01/research/yk/target/debug/deps/liblog-6bd6a1a9417c9b44.rlib \
/home/vext01/research/yk/target/debug/deps/libplain-815d5b934f3c458c.rlib \
/home/vext01/research/yk/target/debug/deps/libscroll-57c304c9c9aa4f19.rlib \
/home/vext01/research/yk/target/debug/deps/libuuid-d9fa09a0ac505087.rlib \
/home/vext01/research/yk/target/debug/deps/libtarget_lexicon-bd6c9c95040de744.rlib \
/home/vext01/research/yk/target/debug/deps/libfailure-883b6313101c519f.rlib \
/home/vext01/research/yk/target/debug/deps/libhwtracer-4a7fcfc6cdb25d08.rlib \
/home/vext01/research/yk/target/debug/deps/libtempfile-f73c3fca6b62eb80.rlib \
/home/vext01/research/yk/target/debug/deps/librand-df0ca11adb03b8e3.rlib \
/home/vext01/research/yk/target/debug/deps/librand_chacha-276a59e9166a9193.rlib \
/home/vext01/research/yk/target/debug/deps/libc2_chacha-170e0ce215266f6e.rlib \
/home/vext01/research/yk/target/debug/deps/libppv_lite86-8dd4ff65271756be.rlib \
/home/vext01/research/yk/target/debug/deps/librand_core-4c118f0513457ff6.rlib \
/home/vext01/research/yk/target/debug/deps/libgetrandom-a724117bf2304247.rlib \
/home/vext01/research/yk/target/debug/deps/libremove_dir_all-635dd99a7c406912.rlib \
/home/vext01/research/yk/target/debug/deps/libcfg_if-6454a07998dfdf77.rlib \
/home/vext01/research/yk/target/debug/deps/libtime-de6100a3b17d5591.rlib \
/home/vext01/research/yk/target/debug/deps/liblibc-7376e8de49ab6c4d.rlib \
/home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib \
/home/vext01/research/yk/target/debug/deps/librmp_serde-337cde3a4d7cf067.rlib \
/home/vext01/research/yk/target/debug/deps/libserde-af0b54eec19c1f21.rlib \
/home/vext01/research/yk/target/debug/deps/librmp-3e2e145986c5b5a2.rlib \
/home/vext01/research/yk/target/debug/deps/libnum_traits-e132ced7a5978735.rlib \
/home/vext01/research/yk/target/debug/deps/libbyteorder-06c02cccfe57c005.rlib \
/home/vext01/research/yk/target/debug/deps/libfallible_iterator-72f65c2f6c00d6f7.rlib \
/home/vext01/research/yk/target/debug/deps/liblazy_static-40baa21fb02fe58c.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-fa7c5db992c603ae.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libterm-677b7a33a112844b.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-3823ca10bcc34fef.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-b085949ade5be118.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-937f89c7b4331592.rlib \
-Wl,--start-group \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d5a0f5d9c2ecbc13.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-6214af4642f83019.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-d853b38ef82d1b80.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-b5c8492ce140f2f4.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-4f884e18d6db8201.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-55bf2675880f6c0f.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e80dead6761c88af.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-a0079eacbe814aa8.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-eaebc19628616584.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-041597c76bfe99c8.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4f9776276b6dc54c.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-f0c8c9c0de0535e4.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-cf28f55e983f3931.rlib \
-Wl,--end-group \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-f4dd3b487c184fe0.rlib \
-Wl,-Bdynamic \
-lipt \
-lutil \
-lutil \
-ldl \
-lrt \
-lpthread \
-lgcc_s \
-lc \
-lm \
-lrt \
-lpthread \
-lutil \
-lutil \
-Wl,--no-gc-sections \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2qajgdgxxha7pskm.rcgu.o
这成功了,但是当我们检查生成的二进制文件时,.yksir_ykpack
丢失了:
$ readelf --section-headers /home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 2>/dev/null | grep 'yksir_ykpack'
$
.yksir_yktrace
部分 是 在二进制文件中:
$ readelf --section-headers /home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 2>/dev/null | grep 'yksir_yktrace'
...
[31] .yksir_yktrace PROGBITS 0000000000000000 009ba0e0
0000000000078ed3 0000000000000000 0 0 16
有人知道这是为什么吗? .yksir_ykpack
去哪儿了?
我试过删除 -Wl,--as-needed
并向上移动 -Wl,--no-gc-sections
。不开心。
谢谢!
我想通了。
这里的关键细节是 Rust .rlib
文件是静态库。与 .o
目标文件不同,当 linking 静态库(通常是 .a
文件)时,linker 使用解析步骤仅引入尚未定义的符号和没有别的。
这可以通过这个最小的例子看出:
all: main_a main_o main_a_whole dump
# Generate text files to use as the contents of the sections.
my_section1.raw:
echo "mydata1" > $@
my_section2.raw:
echo "mydata2" > $@
# Generate object files for the sections.
my_section1.o: my_section1.raw
objcopy --input-target binary \
--output-target=elf64-x86-64 \
--binary-architecture i386:x86-64 \
--rename-section .data=.my_section1 \
my_section1.raw $@
my_section2.o: my_section2.raw
objcopy --input-target binary \
--output-target=elf64-x86-64 \
--binary-architecture i386:x86-64 \
--rename-section .data=.my_section2 \
my_section2.raw $@
# And for section1 only, we will make a static lib.
my_section1.a: my_section1.o
ar rcs $@ my_section1.o
# A "main" stub to link our objects to.
main.c:
echo "void main(void) {}" > main.c
# Now make some binaries using varying linkage configurations.
# main_o is made from the object files.
main_o: main.o my_section1.a my_section2.o
${CC} -o $@ my_section1.o my_section2.o main.o
# main_a uses the static lib for section1 and the object file for section2.
main_a: main.o my_section1.a my_section2.o
${CC} -o $@ my_section1.a my_section2.o main.o
# main_a_whole is the same as main_a, but uses --whole-archive when linking section1.
main_a_whole: main.o my_section1.a my_section2.o
${CC} -o $@ -Wl,--whole-archive my_section1.a -Wl,--no-whole-archive my_section2.o main.o
# Print the sections of interest from the resulting binaries.
dump:
@echo "\n>>> main_o sections"
objdump -h main_o | grep my_section
@echo "\n>>> main_a sections"
objdump -h main_a | grep my_section
@echo "\n>>> main_a_whole sections"
objdump -h main_a_whole | grep my_section
clean:
rm -f *.o *.a main_a main_o main_a_whole *.raw main.c
当运行时,我们得到:
>>> main_o sections
objdump -h main_o | grep my_section
23 .my_section1 00000008 0000000000004028 0000000000004028 00003028 2**0
24 .my_section2 00000008 0000000000004030 0000000000004030 00003030 2**0
>>> main_a sections
objdump -h main_a | grep my_section
23 .my_section2 00000008 0000000000004028 0000000000004028 00003028 2**0
>>> main_a_whole sections
objdump -h main_a_whole | grep my_section
23 .my_section1 00000008 0000000000004028 0000000000004028 00003028 2**0
24 .my_section2 00000008 0000000000004030 0000000000004030 00003030 2**0
注意使用 --whole-archive
强制加载整个静态库。这可能是不可取的,因为您可能希望完全 link 只有一个部分,这不能直接完成 AFAICS。在这种情况下,您可以使用 ar
或 objcopy
和 link 来提取部分。