elfnote

Updated: April 19, 2023

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

Syntax:

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

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

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

Runs on:

QNX Neutrino, Linux, macOS, 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. Take the note format for QNT_STACK, for example, which consists of three fields:
  • The total size
  • The pre-allocated size
  • Whether the stack is executable
Thus, a 64K stack, 32K pre-allocated, non-executable note takes the form:
elfnote -nQNX -tQNT_STACK -Fn -m 64k,32k,1 file
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 size
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. . The following symbolic names can be used with -t:
  • 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
Increase verbosity.
-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.
Use -S, -L and -x for the simplest setting of stack parameters.
  • Change stack to be executable, preserving existing size and allocation values:
    elfnote -x exec file
  • Change stack to be non-executable, preserving existing size and allocation values:
    elfnote -x noexec file

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 examples explain how to modify QNT_STACK to set stack size and stack alloc using:
  • a raw hexadecimal value (either comma-separated or not), the equivalent command is:
    elfnote -t QNT_STACK -Fx -m 00,00,02,00,00,10,00,00,01,00,00,00 filename
  • a numeric format, the equivalent commands are:
    elfnote -S 131072 -L -x noexec filename
    elfnote -t QNT_STACK -Fn -m stack size,stack prealloc size,flags filename
    The only current flag is QNX_STACK_NOTEXECUTABLE 1.
    Note: Apply the n format string repeatedly to parse the individual, comma-separated numeric elements.
  • a mixed format, the equivalent commands are:
    elfnote -n QNX -t QNT_STACK -m 000002000010000001000000 filename
    elfnote -t QNT_STACK -Fx -m 00,00,02,00,00,10,00,00,01,00,00,00 filename
    elfnote -t QNT_STACK -Fn -m 128K,4K,1 filename
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