You can determine the extended name of a function at
execution
time by taking the following steps. Note that all offsets are in decimal.
-
Find the external symbol name, stored at offset
5 in the function prolog (except in a very large function). During execution,
general register 5 points to the start of the function prolog. Alternately,
you can access the function entry point via the register 15 value stored at
offset 16 in the previous save area. This technique is effective regardless
of function size.
-
Get the address of the constants CSECT from offset
32 in the function prolog or from general register 4.
-
Determine the address of the run-time constants
CSECT. This address is located at offset 8 in the constants CSECT.
-
Determine the address of the extended function
names CSECT. This address is located at offset 12 in the run-time constants
CSECT.
-
Retrieve the fullword value (the SNAME hash value)
located at offset 0 in the extended function names CSECT.
-
Convert the six digits of the external symbol
to binary.
-
If the result of this conversion is greater than
the SNAME hash value, subtract the hash value. The result is the offset of
the extended name in the CSECT. The first halfword at this offset is the length
of the extended name followed by the extended name itself.
To get a clearer picture of the content of these CSECTs,
examine an OMD370 listing. Use the
verbose
option to include the extended
names CSECTs in the disassembly. For more information about the constants
CSECT and the run-time constants CSECT, refer to Compiler-generated Names. Code Generation Conventions also
contains more information about CSECT addressing at execution time.
The PRTNAME function is an
assembler language function that prints the name of the function pointed to
by its argument. This function illustrates the process explained above. The
prototype for PRTNAME is the following:
void prtname(_remote void (*) (void));
If the argument points to a function with an extended
name, the extended name is printed. Otherwise, the name stored in the function
prolog is printed.
The PRTNAME Function shows the PRTNAME function.
The PRTNAME Function
PRTNAME@ CSECT
CREGS USING
USING CPROLOG,R2
PRTNAME CENTRY DSA=DSALEN
L R2,0(,R1) R2 -> function pointer
L R2,0(,R2) R2 -> function prolog
LA R3,CPROFNM R3 -> function name
CLC =C'@@',CPROFNM Start with @@?
BNE NOTEXTND No - not an extended name
L R4,CPROCONS R4 -> constant CSECT
L R4,8(,R4) R4 -> run-time constants CSECT
L R4,12(,R4) R4 -> extended function names CSECT
LTR R4,R4 Set to 0 if CSECT not present.
BZ NOTEXTND
L R0,0(,R4) R0 = SNAME hash value
PACK EXTSYM(8),CPROFNM+2(6) Convert 6 digits in external
CVB R5,EXTSYM symbol name to binary.
CR R5,R0 Is symbol less than hash value?
BNH FOUND If so, don't subtract.
SR R5,R0 If not, subtract hash value.
FOUND DS 0H
AR R5,R4 R5 -> length of extended name
LH R0,0(,R5) R0 = length
ST R0,NAMELEN Store in printf parm list.
LA R5,2(,R5) R5 -> extended name
ST R5,NAME Store in printf parm list.
B CALLPRTF Go call printf.
*
* Handle function names that aren't extended.
*
NOTEXTND DS 0H
MVC NAMELEN,=F'8' Store length in plist.
ST R3,NAME Store pointer to name in plist.
*
* Call printf to print the function name.
*
CALLPRTF DS 0H
MVC FORMAT,=A(FMTSTR)
LA R1,PARMLIST
L R15,=V(PRINTF)
BALR R14,R15
CEXIT DSA=DSALEN,RC=0
DROP R2
LTORG
FMTSTR DC C'"%.*s"',X'1500' printf format
COPY DSA
EXTSYM DS 8C decimal-to-binary conversion area
PARMLIST DS 0F printf parameter list
FORMAT DS A
NAMELEN DS A
NAME DS A
DSALEN EQU *-DSA
COPY CPROLOG
COPY CRAB
Two tests are performed to discover if the function
has an extended name. The first test determines if the name stored in the
function prolog begins with
@@
. The second test determines if the address of
the extended function names CSECT is nonzero. If the
NOXFNMKEEP
COOL option
is specified, this address is set to 0, and the extended function names CSECT
is deleted from the output object file.
Copyright © 2001
by SAS Institute Inc., Cary, NC, USA. All rights reserved.