Use of AR and NM commands

Source: Internet
Author: User
Use of AR and NM commands

When there are frequently used modules in our program and such modules are also used in other programs, we should generate libraries based on the idea of software reuse so that later programming can reduce R & DCodeQuantity. Here we will introduce the two commands AR and Nm for database operations.

By wing, source: only_you

When there are frequently used modules in our program and such modules are also used in other programs, we should generate Libraries Based on the software reuse idea, this allows future programming to reduce the amount of R & D code. Here we will introduce the two commands AR and Nm for database operations.

1. Basic ar usage

The ar command can be used to create and modify databases, and a single module can be proposed from the database. A library is a separate document that contains other documents organized according to a specific structure (referred to as the member of this library document ). The content, mode, timestamp, owner, group, and other attributes of the original document are kept in the library document.

The format of the Ar command is as follows:
Ar [-] [abcfilnopssuvv] [membername] [count] archivefiles...

For example, we can use ar rvl ibtest. A hello. O hello1.o to generate a library named test, which can be linked with-ltest. The library contains two modules: Hello. O and hello1.o. The option can contain '-' or none. Next let's take a look at the operation options and any options of the command. Now we call part of the operation option, while the part of [abcfilnopssuvv] is called any option.

The operation options in can only use one of them in the command. Their meanings are as follows:
D: delete a module from the database. Specify the module to be deleted based on the original document name of the module. If any option V is used, each deleted module is listed.

M: This operation is a member moving in a library. If several modules in the library have the same symbolic definition (for example, function definition), the position order of members is very important. If no option is specified, any specified member will be moved to the end of the database. You can also use the 'A', 'B', or 'I' option to move to the specified position.

P: displays the specified members in the database to the standard output. If any option V is specified, the member name is displayed before the content of the output member. If no member name is specified, any documents in the database will be displayed.

Q: Fast append. Add a new module to the end of the database. Do not check whether replacement is required. The 'A', 'B', or 'I' option does not affect this operation. The module always appends the end of the library. If any option V is used, each module is listed. In this case, the symbol table of the library is not updated. You can use 'ars' or ranlib to update the index of the symbol table of the library.

R: Insert a module (replace) into the database ). If the inserted Module name already exists in the Database, replace the module with the same name. If one of the modules does not exist in the library, ar displays an error message and does not replace other modules with the same name. By default, new members are added at the end of the database, and other options can be used to change the position of the added member.

T: displays the list of modules in the database. Generally, only the module name is displayed.

X: extract a member from the database. If the module to be extracted is not specified, any module in the library is extracted.

The following describes any options that can be used with operation options:
A: Add a new document after an existing member of the database. If any option A is used, an existing member name should be specified for the membername parameter in the command line.

B: Add a new document before an existing member of the database. If any option B is used, an existing member name should be specified for the membername parameter in the command line.

C: Create a database. Whether or not the database exists will be created.

F: truncates the specified name in the database. By default, the document name length is unrestricted. You can use this parameter to shorten the document name to ensure compatibility with other systems.

I: Add a new document before an existing member of the database. If any option I is used, an existing member name (similar to any option B) should be specified for the membername parameter in the command line ).

L: Not used yet

N: used with the Count parameter. The number of extracted or output files is specified when multiple identical document names exist in the database.

O: when a Member is extracted, the original data of the member is retained. If this option is not specified, the extracted module time is marked as the extracted time.

P: use the full path name for document name matching. Ar cannot use full path names when creating a library (such library documents do not comply with POSIX standards), but some tools can.

S: Write a target document index to the database, or update an existing target document index. This action is even performed for libraries that have not changed. Doing the ARS for a library is equivalent to doing the ranlib for the library.

S: do not create the index of the target document, which can speed up the creation of a large library.

U: Generally, the ARR command... Insert any listed documents to the library. You can use this option if you only want to insert documents in the list document that are newer than the documents with the same name in the library. This option is only used for r operation.

V: This option is used to display additional information about the operation options.

V: displays the AR version.

2. Basic usage commands of Nm

Nm is used to list the symbols of the target document. The following is the format of the NM command:
NM [-A | -- debug-Syms] [-G | -- extern-only] [-B]
[-C | -- demangle] [-d | -- Dynamic] [-S | -- print-armap]
[-O | -- print-file-name] [-N | -- Numeric-Sort]
[-P | -- no-Sort] [-r | -- reverse-Sort] [-- size-Sort]
[-U | -- undefined-only] [-L | -- line-numbers] [-- help]
[-- Version] [-tradix | -- Radix = Radix]
[-P | -- portability] [-fformat | -- format = format]
[-- Target = bfdname] [objfile...]

If the target document is not specified for the NM command, Nm assumes that the target document is a. Out. The following lists any options for this command. Most options include short formats starting with "-" And long formats starting.
-A,-o, or -- print-file-Name: add the document name before the names of each symbol, instead of displaying the document name only once before any symbol in this document.

For example, the output of nmlibtest. A is as follows:

Cpthread. O:
20170068tmain _ 8 cpthreadpv
20170038tstart _ 8 cpthread
20170014t _. _ 8 cpthread
Optional bytes T _ 8 cpthread
00000000? _ Frame_begin __
.......................................

The output of nm-A is as follows:

Libtest. A: cpthread. O: 00000068tmain _ 8 cpthreadpv
Libtest. A: cpthread. O: 00000038tstart _ 8 cpthread
Libtest. A: cpthread. O: 00000014t _. _ 8 cpthread
Libtest. A: cpthread. O: commandid T _ 8 cpthread
Libtest. A: cpthread. O: 00000000? _ Frame_begin __

-A or -- debug-Syms: displays debugging symbols.

-B: equivalent to -- format = BSD, used to be compatible with MIPS nm.

-C or -- demangle: decodes a low-level symbolic name (demangle) into a user-level name. This makes the C function name readable.

-D or -- Dynamic: displays dynamic symbols. This option is only valid for dynamic targets (such as shared libraries of a specific type.

-Fformat: Output in format. Format can select BSD, sysv, or POSIX. This option is useful in GNU nm. The default value is BSD.

-G or -- extern-only: displays only external symbols.

-N,-V, or -- Numeric-sort: sort by the address corresponding to the symbol, rather than by the character order of the symbol name.

-P or -- no-sort: it is displayed in the order of symbols encountered in the target document and is not sorted.

-P or -- Portability: Use the posix.2 standard output format instead of the default output format. It is equivalent to using any option-fposix.

-S or -- print-armap: contains the index when the symbol of the member in the column warehouse picking. The index content includes: Which modules contain the Mappings of names.

-R or -- reverse-sort: reverse the order (for example, ascending to descending ).

-- Size-sort: Sort symbols by size. The size is calculated based on the value of a symbol and the value of another symbol.

-Tradix or -- Radix = Radix: Use the radix hexadecimal notation to display the symbolic value. Radix can only represent "D" in decimal format, "O" in octal format, or "x" in hexadecimal format.

-- Target = bfdname: Specify the format of the target code, rather than the default format of the system.

-U or -- undefined-only: Only undefined symbols (those external symbols) are displayed ).

-L or -- line-numbers: For each symbol, use debugging information to try to find the document name and row number. For the defined symbols, find the line number of the symbol address. For undefined symbols, find the row number pointing to the symbol relocation entry. If you can find the row number information, it is displayed after the symbol information.

-V or -- version: displays the NM version number.

-- help: displays any options of nm.
ar CS libmy. A // create a library
ar Rs libmy. A 1.o// Add a module
ar t libmy. A // display the module in the library
ar d libmy. A 1.o// delete a module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.