Disclaimer: Whatever I suggested in my blog is what I would do, it does not necessarily mean the only way to do it.
Ridding or modifying hardware capabilities info
Yes, yes, time to start blogging at Sun. Give people more info on Sun Studio ...
Ever experienced the following case before? You created an app targetted for certain "newer" platforms, then one day came across an "older" machine and cautiouslessly tried to run your app on it. What happened? When a new instruction of the newer machine was executed on an older one, which did not recognize it, simply ended with a rude message from the O.S., "Invalid Instruction". At this stage, it may take some effort to figure out the culpit.
Solaris 10 has a new feature, namely the Hardware Capabilities checking machanism which stops it with the runtime linker before running it.
Let's say we have a pack.o which contains x86's SSE2 and AMD's 3DNow instructions. You can check it using a file command:
% file pack.o
pack.o: ELF 32-bit LSB relocatable 80386 Version 1 [SSE2 AMD_3DNow]
Apparently, any apps linking in pack.o will not be able to run under a non-AMD machine. The runtime linker under Solaris 10 will return an error:
% a.out
ld.so.1: a.out: fatal: hardware capability unsupported: 0x100 [ AMD_3DNow ]
The trick is the compiler during the assembly phase puts out a section marking all the encountered instructions as listed in /usr/include/sys/auxv_386.h. The runtime linker will check the combined bits of all instructions against the underlying platform.
But there is need for exception. Some code are written to have different fragments of code relating to different platforms and a choice is made based on the runtime checking of the CPUID bits.
In this case a possible resolution may be
% cc -S -xarch=sse2 file.c
% fbe -nH file.s <-- file.o will have no marking
For relocatable object file:
% more mapfile
hwcap_1 = SSE2 OVERRIDE;
% cc -c -xarch=sse2 file.c -o file_pre.o
% ld -r -Mmapfile -o file.o file_pre.o
% file file_pre.o
file_pre.o: ELF 32-bit LSB relocatable 80386 Version 1 [SSE2 AMD_3DNow]
% file file.o
file.o: ELF 32-bit LSB relocatable 80386 Version 1 [SSE2]
For shared library:
% more mapfile
hwcap_1 = SSE2 OVERRIDE;
% cc -Mmapfile -G -o file.so file.o
% file file.o
file.o: ELF 32-bit LSB relocatable 80386 Version 1 [SSE2 AMD_3DNow]
% file file.so
file.so: ELF 32-bit LSB dynamic lib 80386 Version 1 [SSE2], dynamically linked, not stripped
Likewise for executable file.
One last trick, if you have a .s assembly file, you can assemble it with -showimap for verbose instruction category output.
% fbe -showimap pack.s
line 47: movdl => SSE2
line 51: movdl => SSE2
line 56: prefetchw => 3DNow
line 57: movq => SSE2
...
Posted at 06:00PM Jan 13, 2006 by alblog in Sun | Comments[0]
Today's Page Hits: 2