Nm (Unix)

Page d’aide sur l’homonymie

Pour les articles homonymes, voir NM.

Cet article est une ébauche concernant l’informatique.

Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants.

nm est un utilitaire Unix servant à examiner les fichiers binaires.

Il fait partie des outils GNU Binutils.

Exemple

Code source :

/*
 * File name: test.c
 * For C code compile with: 
 * gcc -c test.c
 *
 * For C++ code compile with:
 * g++ -c test.cpp
 */

int global_var;
int global_var_init = 26;

static int static_var;
static int static_var_init = 25;

static int static_function()
{
	return 0;
}

int global_function(int p)
{
	static int local_static_var;
	static int local_static_var_init=5;

	local_static_var = p;

	return local_static_var_init + local_static_var;
}

int global_function2()
{
	int x;
	int y;
	return x+y;
}

#ifdef __cplusplus
extern "C"
#endif
void non_mangled_function()
{
	// I do nothing
}

int main(void)
{
	global_var = 1;
	static_var = 2;

	return 0;
}

Si le code est compilé avec le compilateur C gcc, la sortie de la commande nm est :

# nm test.o
0000000a T global_function
00000025 T global_function2
00000004 C global_var
00000000 D global_var_init
00000004 b local_static_var.1255
00000008 d local_static_var_init.1256
0000003b T main
00000036 T non_mangled_function
00000000 t static_function
00000000 b static_var
00000004 d static_var_init

Si le compilateur C++ est utilisé, la sortie change :

# nm test.o
0000000a T _Z15global_functioni
00000025 T _Z16global_function2v
00000004 b _ZL10static_var
00000000 t _ZL15static_functionv
00000004 d _ZL15static_var_init
00000008 b _ZZ15global_functioniE16local_static_var
00000008 d _ZZ15global_functioniE21local_static_var_init
         U __gxx_personality_v0
00000000 B global_var
00000000 D global_var_init
0000003b T main
00000036 T non_mangled_function

La première colonne représente les valeurs des symboles, la seconde leurs types, et la troisième leurs noms[1].

On peut également voir les fonctions que contient un fichier binaire.

Notes et références

  1. Library, linux
v · m
Commandes Unix
Aide
  • uname
  • apropos
  • help
  • file
  • history
  • info
  • man
  • type
  • whatis
Environnement utilisateur
  • env
  • dmesg
  • finger
  • halt
  • id
  • init
  • logname
  • mesg
  • passwd
  • reboot
  • shutdown
  • su
  • sudo
  • talk
  • uptime
  • w
  • wall
  • who
  • whoami
  • write
Gestion de processus
Manipulation de texte
Programmation shell
Recherche
Réseau
Système de fichiers
Divers
  • icône décorative Portail de l’informatique