stein@pixelpump.osc.edu (Rick 'Transputer' Stein) (05/26/89)
I have some questions about how a compiler constructs a symbol table. My first question is: 1) Will a compiler "arbitrarily" move structure elements to enforce alignment on a boundary? 2) If the compiler does move a structure element, does this imply that the element no longer maintains the same offset value from the beginning of the structure? Are all the other elements moved (rearranged) as well? 3) Is there a way, or even some general guidelines, for creating a portable image of the symbol table, in the sense of knowing where the variables are located in memory? By portable I mean that I can create a data structure which contains sufficient elements and information to describe the physical layout of a data psect without having detailed or explicit knowledge of the compiler internals. I'm asking these questions because I'd like to build a real-time monitor for poking/peeking at global data. To do this, I believe that I must build a data dictionary, where each entry is inserted into a psect. If I explicitly organize the psect in this way, I know the byte offset of each variable, its type, dimension, etc. from the psect head. When the psect is loaded into memory, I can take the address of the psect head to determine the physical address of the each psect member with some simple address arithmetic. Can this monitor process, and the symbol table structure be built in a compiler and machine portable way? Thanks. -=- Richard M. Stein (aka Rick 'Transputer' Stein) Concurrent Software Specialist @ The Ohio Supercomputer Center Ghettoblaster vacuum cleaner architect and Trollius semi-guru Internet: stein@pixelpump.osc.edu [C compilers have the right to lay out structures any way they see fit, unless the ANSI committee changed the rules. In reality, I've never seen a compiler do more than leave a hole in the structure to move up an element that would otherwise be misaligned. All instances of a given kind of structure are laid out the same way. You could probably make your code somewhat parameterized to deal with machines that do or do not have alignment rules, but I suspect you'll end up having to know more about what's going on than you'd like. By the way, I assume that by psect you mean a writable data segment. -John] -- Send compilers articles to compilers@ima.isc.com or, perhaps, Levine@YALE.EDU Plausible paths are { decvax | harvard | yale | bbn}!ima Please send responses to the originator of the message -- I cannot forward mail accidentally sent back to compilers. Meta-mail to ima!compilers-request