4343
4444#if defined(_CALL_ELF ) && _CALL_ELF == 2
4545#define R2_STACK_OFFSET 24
46+
47+ /* An address is simply the address of the function. */
48+ typedef unsigned long func_desc_t ;
49+
50+ static func_desc_t func_desc (unsigned long addr )
51+ {
52+ return addr ;
53+ }
54+ static unsigned long func_addr (unsigned long addr )
55+ {
56+ return addr ;
57+ }
58+ static unsigned long stub_func_addr (func_desc_t func )
59+ {
60+ return func ;
61+ }
62+
63+ /* PowerPC64 specific values for the Elf64_Sym st_other field. */
64+ #define STO_PPC64_LOCAL_BIT 5
65+ #define STO_PPC64_LOCAL_MASK (7 << STO_PPC64_LOCAL_BIT)
66+ #define PPC64_LOCAL_ENTRY_OFFSET (other ) \
67+ (((1 << (((other) & STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2)
68+
69+ static unsigned int local_entry_offset (const Elf64_Sym * sym )
70+ {
71+ /* sym->st_other indicates offset to local entry point
72+ * (otherwise it will assume r12 is the address of the start
73+ * of function and try to derive r2 from it). */
74+ return PPC64_LOCAL_ENTRY_OFFSET (sym -> st_other );
75+ }
4676#else
4777#define R2_STACK_OFFSET 40
78+
79+ /* An address is address of the OPD entry, which contains address of fn. */
80+ typedef struct ppc64_opd_entry func_desc_t ;
81+
82+ static func_desc_t func_desc (unsigned long addr )
83+ {
84+ return * (struct ppc64_opd_entry * )addr ;
85+ }
86+ static unsigned long func_addr (unsigned long addr )
87+ {
88+ return func_desc (addr ).funcaddr ;
89+ }
90+ static unsigned long stub_func_addr (func_desc_t func )
91+ {
92+ return func .funcaddr ;
93+ }
94+ static unsigned int local_entry_offset (const Elf64_Sym * sym )
95+ {
96+ return 0 ;
97+ }
4898#endif
4999
50100/* Like PPC32, we need little trampolines to do > 24-bit jumps (into
@@ -56,7 +106,7 @@ struct ppc64_stub_entry
56106 u32 jump [7 ];
57107 u32 unused ;
58108 /* Data for the above code */
59- struct ppc64_opd_entry opd ;
109+ func_desc_t funcdata ;
60110};
61111
62112/*
@@ -225,7 +275,7 @@ static Elf64_Sym *find_dot_toc(Elf64_Shdr *sechdrs,
225275
226276 for (i = 1 ; i < numsyms ; i ++ ) {
227277 if (syms [i ].st_shndx == SHN_UNDEF
228- && strcmp (strtab + syms [i ].st_name , ". TOC." ) == 0 )
278+ && strcmp (strtab + syms [i ].st_name , "TOC." ) == 0 )
229279 return & syms [i ];
230280 }
231281 return NULL ;
@@ -295,7 +345,7 @@ static inline unsigned long my_r2(Elf64_Shdr *sechdrs, struct module *me)
295345/* Patch stub to reference function and correct r2 value. */
296346static inline int create_stub (Elf64_Shdr * sechdrs ,
297347 struct ppc64_stub_entry * entry ,
298- struct ppc64_opd_entry * opd ,
348+ unsigned long addr ,
299349 struct module * me )
300350{
301351 long reladdr ;
@@ -313,33 +363,31 @@ static inline int create_stub(Elf64_Shdr *sechdrs,
313363
314364 entry -> jump [0 ] |= PPC_HA (reladdr );
315365 entry -> jump [1 ] |= PPC_LO (reladdr );
316- entry -> opd .funcaddr = opd -> funcaddr ;
317- entry -> opd .r2 = opd -> r2 ;
366+ entry -> funcdata = func_desc (addr );
318367 return 1 ;
319368}
320369
321- /* Create stub to jump to function described in this OPD: we need the
370+ /* Create stub to jump to function described in this OPD/ptr : we need the
322371 stub to set up the TOC ptr (r2) for the function. */
323372static unsigned long stub_for_addr (Elf64_Shdr * sechdrs ,
324- unsigned long opdaddr ,
373+ unsigned long addr ,
325374 struct module * me )
326375{
327376 struct ppc64_stub_entry * stubs ;
328- struct ppc64_opd_entry * opd = (void * )opdaddr ;
329377 unsigned int i , num_stubs ;
330378
331379 num_stubs = sechdrs [me -> arch .stubs_section ].sh_size / sizeof (* stubs );
332380
333381 /* Find this stub, or if that fails, the next avail. entry */
334382 stubs = (void * )sechdrs [me -> arch .stubs_section ].sh_addr ;
335- for (i = 0 ; stubs [i ].opd . funcaddr ; i ++ ) {
383+ for (i = 0 ; stub_func_addr ( stubs [i ].funcdata ) ; i ++ ) {
336384 BUG_ON (i >= num_stubs );
337385
338- if (stubs [i ].opd . funcaddr == opd -> funcaddr )
386+ if (stub_func_addr ( stubs [i ].funcdata ) == func_addr ( addr ) )
339387 return (unsigned long )& stubs [i ];
340388 }
341389
342- if (!create_stub (sechdrs , & stubs [i ], opd , me ))
390+ if (!create_stub (sechdrs , & stubs [i ], addr , me ))
343391 return 0 ;
344392
345393 return (unsigned long )& stubs [i ];
@@ -480,7 +528,8 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
480528 return - ENOENT ;
481529 if (!restore_r2 ((u32 * )location + 1 , me ))
482530 return - ENOEXEC ;
483- }
531+ } else
532+ value += local_entry_offset (sym );
484533
485534 /* Convert value to relative */
486535 value -= (unsigned long )location ;
0 commit comments