I wrap a binary file into object file by ld -sectcreate
. The output object contains my custom data:
% otool -s test_rcs_output deep_dark deep_dark.o
test_rcs_output/deep_dark.o:
Contents of (test_rcs_output,deep_dark) section
0000000000000000 e89188e6 a4e5bd83 9e90e59f e79fa3e9
0000000000000010 92e7bb8e 8c80e883 e48db8e4 aee5a4bc
0000000000000020 abbae8b3 0a93bde4
Then the problem comes. If I directly use the object file in the final link stage, the output executable contains my custom data segment/section:
% otool -s test_rcs_output deep_dark t_rcs2_basic
t_rcs2_basic:
Contents of (test_rcs_output,deep_dark) section
000000010013001b e89188e6 a4e5bd83 9e90e59f e79fa3e9
000000010013002b 92e7bb8e 8c80e883 e48db8e4 aee5a4bc
000000010013003b abbae8b3 0a93bde4
But if I firstly archive the object into static library, then link with this static library, the custom segment/section would be lost in the final executable:
% otool -s test_rcs_output deep_dark libtest_rcs_output.a
Archive : libtest_rcs_output.a
......many objects......
libtest_rcs_output.a(deep_dark.o):
Contents of (test_rcs_output,deep_dark) section
0000000000000000 e89188e6 a4e5bd83 9e90e59f e79fa3e9
0000000000000010 92e7bb8e 8c80e883 e48db8e4 aee5a4bc
0000000000000020 abbae8b3 0a93bde4
......many objects......
% otool -s test_rcs_output deep_dark t_rcs2_basic
t_rcs2_basic:
Why the linker uses the data when object files are "plainly" used, but discard them when used from a static library?
And if I really want the objects being archived, how to tell the linker not discarding them?