elfnote

Updated: October 26, 2022

Display or modify the contents of an ELF note (QNX)

Syntax:

elfnote -p [-n name] [-t type] [-v] file

elfnote [-p] [-n name] [-t type] [-F fmt] -m value file [outfile]

elfnote [-pv] [-S num [-L]] [-x [exec | noexec]] file [outfile]

Runs on:

QNX Neutrino, Linux, Mac, Microsoft Windows

Options:

-F fmt
Specifies how to interpret the elements of the -m option's argument.
  • x — The element at the corresponding position in the value string is interpreted as a hexadecimal representation of raw data. For example, if the note description contains numeric types, they must be given in the correct target endian order and represented in hexadecimal bytes. This is the default format if you specify -m.
  • n — The element at the corresponding position in the value string is interpreted as an unsigned integer with an optional size suffix (k, m, or g). The value can be specified as a decimal, octal (0...), or hexadecimal (0x...) number. The number is automatically converted to the correct endian order. This is the default format if you specify -S.
-L
For a QNX note of type QNT_STACK, use lazy stack allocation. Use only when -S is specified.
-m value
Modify the contents of the note, where value is a string that specifies a series of elements separated by a comma. The -F option determines how the individual elements are interpreted. Each -F option value specifies the conversion of one element in value; if the format string has fewer characters than there are elements in value, the format is applied repeatedly.
-n name
The note name to match.
-p
Display (“print”) the notes. If you also use -t to specify a note type, elfnote displays only that type of notes; otherwise, elfnote displays all the notes. If you specify the -m option, elfnote displays the value before modification.
-q
Quiet operation. Do not print warning or error messages.
-S num
The stack size. This option implies -n QNX, -t QNT_STACK, and -Fn.
-t type
The note type to match. Acceptable values are numbers or the following types (defined in <elfdefinitions.h>). When you specify defined types, -n GNU or -n QNX is implied.
  • NT_GNU_BUILD_ID
  • QNT_DEBUG_FULLPATH
  • QNT_DEBUG_RELOC
  • QNT_STACK
  • QNT_GENERATOR
  • QNT_DEFAULT_LIB
  • QNT_CORE_SYSINFO
  • QNT_CORE_INFO
  • QNT_CORE_STATUS
  • QNT_CORE_GREG
  • QNT_CORE_FPREG
  • QNT_LINK_MAP — you can use coreinfo to display this note in core files.

You typically use elfnote to modify QNT_STACK, as described below.

-v
Be extra verbose.
-x [exec | noexec]
Specify whether to update the QNT_STACK note in the binary to request an executable stack:
  • exec — Update the binary to request an executable stack.
  • noexec — Update the binary to request a non-executable stack (the default for newly built binaries).
You can use this option on its own or combine it with -S and -L to update the stack size as well. If you don't specify -S, the stack executability changes but the stack size does not.

Description:

The elfnote utility displays or modifies the contents of a note in an Executable and Linkable Format file.

When you modify the contents of a note, you must specify -t. If -t does not specify a defined type, the note name is not implied and you must also specify -n.

Note:
  • You can't change the size of a note, only its contents.
  • Setting a stack size that's insufficient for the startup of the process, including space for arguments and environment variables (limited by _SC_ARG_MAX or ARG_MAX), may cause unexpected early failures of the process execution.
  • You must specify at least one of the following options: -p, -m, -S or -x; otherwise, elfnote fails.

Examples:

For ldrel-compatible behavior, use options -S and -L. For example, the following command allocates a stack size of 128k at thread creation time:

elfnote -S 128k file

The following command allocates a stack size of 128k, lazy allocated:

elfnote -S 128k -L file

The following example assumes you have a binary containing a note with a name SP_NOTE and type 9, consisting of the four 32-bit values, 100, 200, 300, and 400. To display the note:

# elfnote -p -n SP_NOTE file
Note name = SP_NOTE, type = 9
        hex         : 64000000c80000002c01000090010000

Change the values to 16, 32, 48 and 64:

elfnote -n SP_NOTE -t 9 -F n -m 16,32,48,64 file

Display the changed note:

# elfnote -p -n SP_NOTE file
Note name = SP_NOTE, type = 9
        hex         : 10000000200000003000000040000000

Change the value back to the original by specifying a hex string:

elfnote -n SP_NOTE -t 9 -m 64000000c80000002c01000090010000 file

Display the result again:

# elfnote -p -n SP_NOTE file
Note name = SP_NOTE, type = 9
        hex         : 64000000c80000002c01000090010000