Skip to content

Commit

Permalink
i#2050: Fixes 32-bit compilation, Ubuntu 16.04
Browse files Browse the repository at this point in the history
Affects Ubuntu 16.04, gcc version 5.4.0. When trying to access a label in
DR_ANNOTATION_ATTRIBUTES, we dereference some offset from the GOT. However, in
32-bit mode the linker chokes because it is not given the base register for
the GOT. We specify the base register for 32-bit code only.

Fixes #2050

Review-URL: https://codereview.appspot.com/311480043
  • Loading branch information
toshipiazza committed Jan 4, 2017
1 parent 9d8e8ab commit 24c4f7c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/lib/dr_annotations_asm.h
Expand Up @@ -193,6 +193,7 @@ do { \
*/
# define ANNOTATION_FUNCTION_CLOBBER_LIST "%rax","%rcx","%rdx","%rsi","%rdi","%r8","%r9"
# define _CALL_TYPE
# define ANNOT_LBL(annot, base) #annot"_label@GOT"
# else
/* (mov=5 + bsf/bsr=7) => 0xc */
# define LABEL_REFERENCE_LENGTH "0xc"
Expand All @@ -204,6 +205,10 @@ do { \
*/
# define ANNOTATION_FUNCTION_CLOBBER_LIST "%rax","%rcx","%rdx"
# define _CALL_TYPE , fastcall
/* i#2050: i386 ABI forces us to use the base register as an offset into GOT, which is
* not the case for 64-bit.
*/
# define ANNOT_LBL(annot, base) #annot"_label@GOT(%"base")"
# endif
# define DR_ANNOTATION_ATTRIBUTES \
__attribute__((noinline, visibility("hidden") _CALL_TYPE))
Expand All @@ -215,7 +220,8 @@ do { \
extern const char *annotation##_label; \
__asm__ volatile goto (".byte 0xeb; .byte "LABEL_REFERENCE_LENGTH"; \
mov _GLOBAL_OFFSET_TABLE_,%"LABEL_REFERENCE_REGISTER"; \
bsf "#annotation"_label@GOT,%"LABEL_REFERENCE_REGISTER"; \
bsf "ANNOT_LBL(annotation, LABEL_REFERENCE_REGISTER)", \
%"LABEL_REFERENCE_REGISTER"; \
jmp %l0;" \
::: LABEL_REFERENCE_REGISTER \
: native_run); \
Expand All @@ -236,7 +242,8 @@ do { \
extern const char *annotation##_label; \
__asm__ volatile goto (".byte 0xeb; .byte "LABEL_REFERENCE_LENGTH"; \
mov _GLOBAL_OFFSET_TABLE_,%"LABEL_REFERENCE_REGISTER"; \
bsr "#annotation"_label@GOT,%"LABEL_REFERENCE_REGISTER"; \
bsr "ANNOT_LBL(annotation, LABEL_REFERENCE_REGISTER)", \
%"LABEL_REFERENCE_REGISTER"; \
jmp %l0;" \
::: ANNOTATION_FUNCTION_CLOBBER_LIST \
: native_run); \
Expand Down

0 comments on commit 24c4f7c

Please sign in to comment.