1

Need some help to understand the following code:

  1. What is label?
  2. What does .vectors do in here
  3. What does type \label, %function do?
  4. What does \label: do?
/*
 * Create an entry in the exception vector table, enforcing it is
 * aligned on a 128-byte boundary, as required by the ARMv8 architecture.
 * Use zero bytes as the fill value to be stored in the padding bytes
 * so that it inserts illegal AArch64 instructions. This increases
 * security, robustness and potentially facilitates debugging.
 */

.macro vector_entry  label, section_name=.vectors
.cfi_sections .debug_frame
.section \section_name, "ax"
.align 7, 0
.type \label, %function
.cfi_startproc
\label:
.endm

The code snippet is from ARM ATF code asm_macros.S, I am not an expert on this. Are there any references that introduce these kind of topics.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
syacer
  • 157
  • 6
  • 1
    `\foo` in a macro definition expands the macro parameter named `foo`. https://sourceware.org/binutils/docs/as/Macro.html . `.vectors` is a default value for the 3rd macro arg, the section name. Like `.data` or `.text`, but this one is a custom name. Perhaps for creating entries in a table of interrupt vectors. Look at how the macro gets used. – Peter Cordes Sep 18 '22 at 03:27
  • Thank you, Peter. How about .type \label, %function ? – syacer Sep 18 '22 at 03:29
  • 1
    Did you google the `.type` directive for GNU assembler syntax? The first 3 hits on SO for me are [how to use the gcc assembly command (.type)?](https://stackoverflow.com/q/9292441) / [When are GAS ELF the directives .type, .thumb, .size and .section needed?](https://stackoverflow.com/q/4423211) / [What does the "%object" and "@object" mean in this inline assembly?](https://stackoverflow.com/q/70061418). Also [GAS what does @ and .type do?](https://stackoverflow.com/q/31596266) – Peter Cordes Sep 18 '22 at 03:32
  • 1
    (Correction to my first comment, `section_names` is the 2nd macro arg. label is the 1st. `vector_entry` is the name of the macro.) – Peter Cordes Sep 18 '22 at 03:34
  • It might help to read the assembler manual. – fuz Sep 18 '22 at 13:45
  • `.type \label, %function` would replace `\label` with the label you run the macro with, and specify that it's a function – Sir Archibald Humphrey Sep 19 '22 at 21:24

0 Answers0