Skip to content

Commit 50df9b1

Browse files
committed
Add C2C.atom_needs_GOT_access
This is used on ELF platforms to determine which symbols are relocatable.
1 parent 54d47c0 commit 50df9b1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cfrontend/C2C.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ let atom_is_static a =
5252
with Not_found ->
5353
false
5454

55-
(* Is it possible for symbol [a] to be defined in a DLL? *)
55+
(* Is it possible for symbol [a] to be defined in a DLL?
56+
Yes, unless [a] is defined in the current compilation unit, or is static.
57+
(This criterion is appropriate for macOS and for Cygwin; for ELF,
58+
see [atom_needs_GOT_access] below.) *)
5659
let atom_is_external a =
5760
match Hashtbl.find decl_atom a with
5861
| { a_defined = true } -> false
@@ -61,6 +64,18 @@ let atom_is_external a =
6164
| _ -> true
6265
| exception Not_found -> true
6366

67+
(* In ELF PIC code, the rules are different: all non-static symbols
68+
must be accessed through the GOT, even if they are defined in the
69+
current compilation unit. (This is to allow symbol interposition by
70+
the dynamic loader.) *)
71+
let atom_needs_GOT_access a =
72+
!Clflags.option_fpic &&
73+
begin match Hashtbl.find decl_atom a with
74+
| { a_storage = C.Storage_static } -> false
75+
| _ -> true
76+
| exception Not_found -> true
77+
end
78+
6479
let atom_alignof a =
6580
try
6681
(Hashtbl.find decl_atom a).a_alignment

0 commit comments

Comments
 (0)