🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41957

global labels in a dispatch table

#41957
From: Phil Hampton
Date: Mon, 29 Jan 1996 00:00
37 lines
1594 bytes
I'm trying to figure out how to code up a piece of "self-modifying code"
and am having a bit of difficulty.  Here's the scenario.  Module foo.c has
a (global) label that marks the code that I'll eventually want to modify
(via another program).  Module bar.c is the "modifier code," ie, it will
modify the code at the label declared in foo.c.  So far, so good.  However,
I want to declare a table in bar.c of "code to be modified," and this is
where I'm having trouble.  So,

foo.c
-----
foo()
{
    asm (".globl _f1"); /* declare a global label */
    asm ("_f1:"); /* Insert the label in the stream */
    /* misc code, like NOPs, that will be modified by others at run-time */
}

bar.c
-----
extern ulong f1;
bar()
{
    ulong lookup_table;
    lookup_table = f1;
/*
the above few lines work ok, but I'd rather declare a compile-time
lookup table like this...
    extern void *f1;
    static void *lookup_table[] = { &&f1 };
but this apparently only works for local labels
*/
}

-- 
Phil Hampton   |   hampton@ssdevo.enet.dec.com
               |   ...!decwrl!ssdevo.enet.dec.com!hampton
Technical Details
Message-ID: <4ejfmf$k1q@nntpd2.cxo.dec.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,dd99251f7c973af1,start
X-Google-Attributes: gid11318c,public
From: hampton@ssdevo.enet.dec.com (Phil Hampton)
Subject: global labels in a dispatch table
Date: 1996/01/29
Message-ID: <4ejfmf$k1q@nntpd2.cxo.dec.com>
X-Deja-AN: 137249803
distribution: world
followup-to: gnu.gcc.help
organization: Digital Equipment Corporation
reply-to: hampton@ssdevo.enet.dec.com
newsgroups: gnu.gcc.help