How can I get the architecture of a '.a' file?
You can also skip the ar
command and use readelf, via something like:
readelf -h <archive>.a | grep 'Class\|File\|Machine'
[00:32:15] /usr/lib $ readelf -h libxslt.a | grep 'Class\|File\|Machine'
File: libxslt.a(attrvt.o)
Class: ELF32
Machine: Intel 80386
File: libxslt.a(xslt.o)
Class: ELF32
Machine: Intel 80386
... #Trimmed this, it goes on a bit
File: libxslt.a(transform.o)
Class: ELF32
Machine: Intel 80386
File: libxslt.a(security.o)
Class: ELF32
Machine: Intel 80386
[00:32:24] /usr/lib $
In case it's relevant, here's the other information that you can get from readelf -h
. I just trimmed the above with grep
, obviously:
File: libxslt.a(security.o)
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 2548 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 16
Section header string table index: 13
That output is for one of the object files in libxslt.a
, but it gives the same information for each file.
How do I determine the architecture of an executable binary on Windows 10
The architecture of the executable is written in the Machine field of the COFF header. You can retrieve it programatically or manually with a hex editor:
- Go to offset 0x3C in the file. The four bytes there hold the offset of the COFF header (from the beginning of the file).
- Go to the COFF header pointed by the above field, and advance by four (4) bytes.
- The following two (2) bytes are the Machine field.
You can see PE structure here. The valid Machine field values are listed here.
EDIT: Here's a C code that does that, untested:
int main(int argc, char *argv[]) {
FILE *f = fopen(argv[1], "rb");
uint32_t offset = 0;
fseek(f, 0x3c, SEEK_SET);
fread(&offset, sizeof(offset), 1, f);
fseek(f, offset + 4, SEEK_SET);
uint16_t machine = 0;
fread(&machine, sizeof(machine), 1, f);
printf("Machine: 0x%.4x\n", machine);
}
How can I know which architecture an *.a file is built for?
You can use otool to find out the architecture(s) of a file: otool man page
otool -hv mylibrary.a
Determining the CPU architecture of a static library (LIB) on Windows
Use dumpbin /headers
The machine type is almost the first line you'll get.
It will be 14c for x86 and 8664 for x64
n:>dumpbin lib642.lib /headers
Microsoft (R) COFF/PE Dumper Version
10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved.Dump of file lib642.lib
File Type: LIBRARY
FILE HEADER VALUES
8664 machine (x64
Or
n:>dumpbin Lib32.lib /headers
Microsoft (R) COFF/PE Dumper Version
10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved.Dump of file Lib32.lib
File Type: LIBRARY
FILE HEADER VALUES
14C machine (x86)
Where should I put uploaded files on a Clean Architecture project?
I believe the best place to put an upload folder is in the project root:
- src
- <project files>
- uploads # put your files here
Related Topics
How to Fix "Go Not Root Owned"
Why Does the Wc Command Count One More Character Than Expected
Extending a Script to Loop Over Multiple Files and Generate Output Names
Ffmpeg Fix Watermark Size or Percentage
Remove File Coding Mark But Preserve Its Coding
Using Ld_Preload Mixed 64Bit/32Bit Environment in Linux
How to Count the Number of Occurrences of a String in an Entire File
How to Use Global Arrays in Bash
Cmake Auto Header File Dependency
Tiny "Manually" Created Elf Giving Segmentation Fault
About the Memory Layout of Programs in Linux
How to Build an App for an Old Linux Distribution, and Avoid the Fatal: Kernel Too Old Error
Netfilter-Like Kernel Module to Get Source and Destination Address
Mercurial Hg No Changes Found - Can't Hg Push Out
Creating PDF Invoices - Are There Any Templating Solutions
How to Link to Shared Lib from Shared Lib with Relative Path
Simple Way to Convert Hh:Mm:Ss (Hours:Minutes:Seconds.Split Seconds) to Seconds