aboutsummaryrefslogtreecommitdiffstats
path: root/include/lib/utils.h
diff options
context:
space:
mode:
authorSoby Mathew <soby.mathew@arm.com>2018-10-29 10:56:30 +0000
committerGitHub <noreply@github.com>2018-10-29 10:56:30 +0000
commitcf0886e2f11481f55898f745d288c8705e704f53 (patch)
tree2a1e8c8f334e30fd663e7909c0ea01e7294b7839 /include/lib/utils.h
parentc38941f0c9cce5fcd3996f98ef789ae7481d356b (diff)
parentfc922ca87cc6af8277dc0eb710fc63a2957f0194 (diff)
downloadplatform_external_arm-trusted-firmware-cf0886e2f11481f55898f745d288c8705e704f53.tar.gz
platform_external_arm-trusted-firmware-cf0886e2f11481f55898f745d288c8705e704f53.tar.bz2
platform_external_arm-trusted-firmware-cf0886e2f11481f55898f745d288c8705e704f53.zip
Merge pull request #1644 from soby-mathew/sm/pie_proto
Position Indepedent Executable (PIE) Support
Diffstat (limited to 'include/lib/utils.h')
-rw-r--r--include/lib/utils.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/lib/utils.h b/include/lib/utils.h
index d46d8461d..f324a9909 100644
--- a/include/lib/utils.h
+++ b/include/lib/utils.h
@@ -67,6 +67,29 @@ void zero_normalmem(void *mem, u_register_t length);
* zeroing.
*/
void zeromem(void *mem, u_register_t length);
+
+/*
+ * Utility function to return the address of a symbol. By default, the
+ * compiler generates adr/adrp instruction pair to return the reference
+ * to the symbol and this utility is used to override this compiler
+ * generated to code to use `ldr` instruction.
+ *
+ * This helps when Position Independent Executable needs to reference a symbol
+ * which is constant and does not depend on the execute address of the binary.
+ */
+#define DEFINE_LOAD_SYM_ADDR(_name) \
+static inline u_register_t load_addr_## _name(void) \
+{ \
+ u_register_t v; \
+ /* Create a void reference to silence compiler */ \
+ (void) _name; \
+ __asm__ volatile ("ldr %0, =" #_name : "=r" (v)); \
+ return v; \
+}
+
+/* Helper to invoke the function defined by DEFINE_LOAD_SYM_ADDR() */
+#define LOAD_ADDR_OF(_name) (typeof(_name) *) load_addr_## _name()
+
#endif /* !(defined(__LINKER__) || defined(__ASSEMBLY__)) */
#endif /* __UTILS_H__ */