Need CC flag to align structs on stack

I get a SIGBUS casting sockaddr to sockaddr_in,
but only if sockaddr was declared on the stack.
I am using Forte C/C++ for Sparc WS6U2.
Getting right to the point, is there a way to have
the compiler strictly align structs declared on the
stack, similar to malloc always returning strictly
aligned memory?
Is there any other workaround, other than using
-misalign (bad performance), or fixing each and
every instance of a struct on the stack?
This seems like such a common scenario that
a reasonable workaround should be available.
Thanks in advance,
-Ralph
Details follow...
The following code fragment contains an alignment bug
when casting a sockaddr to a sockaddr_in. The bug
occurs when the sockaddr is declared on the stack, but
not if it is malloc'd. While a call to malloc will return
strictly aligned memory, simply declaring a struct on
the stack will cause it to be aligned only as strictly as
is necessary according to the struct definition. Since
sockaddr requires only short aligned memory, later
casting it to sockaddr_in (a very very frequent case)
is dangerous because it requires long aligned memory.
The sockaddr only requires short alignment, since the
sa_family_t is a short, and the generic address is an
array of char.
However, the sockaddr is very very frequently cast into
a sockaddr_in, which requires long alignment, since the
IPv4 address can be viewed as a 32-bit unsigned integer.
/usr/include/sys/socket.h:
struct sockaddr {
sa_family_t sa_family; /* address family */
char sa_data[14]; /* up to 14 bytes of direct address */
/usr/include/netinet/in.h
struct sockaddr_in {
sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
unsigned char sin_zero[8];
struct in_addr {
union {
struct { uint8_t s_b1, s_b2, s_b3, s_b4; } Sun_b;
struct { uint16_t s_w1, s_w2; } Sun_w;
in_addr_t Saddr;
} Sun;
int SomeClass::SendViaSocket( char *pszMessage )
// some code
struct sockaddr Socket;
// some code
SetIPv4SocketAddress( &Socket );
// some code
void SomeClass::SetIPv4SocketAddress( struct sockaddr *pSocket )
// some code
memset( pSocket, 0, sizeof(*pSocket) );
struct sockaddr_in pIPv4Socket = (struct sockaddr_in)pSocket;
pIPv4Socket->sin_family = AF_INET;
pIPv4Socket->sin_port = htons((unsigned short)nPort);
pIPv4Socket->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
// SIGBUS occurs, sometimes, if the moon is full, in previous line
// some code

Thank you for your reply, but why isn't this a Forte compiler issue?
Are you saying that the compiler has absolutely no influence over
the choice of [%fp - 0x10], e.g. that a Solaris call is made at run-time
in order to allocate space on the stack? If not, how does this involve
the Solaris gurus? Even so, the comiler could still allocate more than
is needed to ensure that %fp is suitably aligned after the fact. It would
appear that this is actually default behavior for the gcc compiler.
(dbx) list -i 489 +2
489 pDestIPAddr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
0x00299a50: GetTargetAddress+0x00d0: sethi %hi(0x7f000000), %l1
0x00299a54: GetTargetAddress+0x00d4: or %l1, 0x1, %l1
0x00299a58: GetTargetAddress+0x00d8: ld [%fp - 0x10], %l0 <---------- look here ------
0x00299a5c: GetTargetAddress+0x00dc: st %l1, [%l0 + 0x4]
*** SIGBUS frequently occurs in previous machine instruction ***
I understand that throwing the -misalign CC flag enables the kernel
memory alignment trap handler to interpret byte-wise access after
a failed long-word access, instead of generating a SIGBUS signal.
Does anyone know the official name of this hardware trap, and/or
how to use the dbx debugger to detect when/if it has occurred?
Or is that not possible because the trap occurs entirely in kernel?
Can anyone confirm that -misalign has a performance impact only
when/if the memory alignment trap handler is invoked?
Can anyone point me to a better forum if this one is inappropriate?
Thanks,
-Ralph

Similar Messages

  • Need a cc flag to align structs on stack

    I get a SIGBUS casting sockaddr to sockaddr_in,
    but only if sockaddr was declared on the stack.
    I am using Forte C/C++ for Sparc WS6U2.
    Getting right to the point, is there a way to have
    the compiler strictly align structs declared on the
    stack, similar to malloc always returning strictly
    aligned memory?
    Is there any other workaround, other than using
    -misalign (bad performance), or fixing each and
    every instance of a struct on the stack?
    This seems like such a common scenario that
    a reasonable workaround should be available.
    Thanks in advance,
    -Ralph
    Details follow...
    The following code fragment contains an alignment bug
    when casting a sockaddr to a sockaddr_in. The bug
    occurs when the sockaddr is declared on the stack, but
    not if it is malloc'd. While a call to malloc will return
    strictly aligned memory, simply declaring a struct on
    the stack will cause it to be aligned only as strictly as
    is necessary according to the struct definition. Since
    sockaddr requires only short aligned memory, later
    casting it to sockaddr_in (a very very frequent case)
    is dangerous because it requires long aligned memory.
    The sockaddr only requires short alignment, since the
    sa_family_t is a short, and the generic address is an
    array of char.
    However, the sockaddr is very very frequently cast into
    a sockaddr_in, which requires long alignment, since the
    IPv4 address can be viewed as a 32-bit unsigned integer.
    /usr/include/sys/socket.h:
    struct sockaddr {
    sa_family_t sa_family; /* address family */
    char sa_data[14]; /* up to 14 bytes of direct address */
    /usr/include/netinet/in.h
    struct sockaddr_in {
    sa_family_t sin_family;
    in_port_t sin_port;
    struct in_addr sin_addr;
    unsigned char sin_zero[8];
    struct in_addr {
    union {
    struct { uint8_t s_b1, s_b2, s_b3, s_b4; } Sun_b;
    struct { uint16_t s_w1, s_w2; } Sun_w;
    in_addr_t Saddr;
    } Sun;
    int SomeClass::SendViaSocket( char *pszMessage )
    // some code
    struct sockaddr Socket;
    // some code
    SetIPv4SocketAddress( &Socket );
    // some code
    void SomeClass::SetIPv4SocketAddress( struct sockaddr *pSocket )
    // some code
    memset( pSocket, 0, sizeof(*pSocket) );
    struct sockaddr_in pIPv4Socket = (struct sockaddr_in)pSocket;
    pIPv4Socket->sin_family = AF_INET;
    pIPv4Socket->sin_port = htons((unsigned short)nPort);
    pIPv4Socket->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    // SIGBUS occurs, sometimes, if the moon is full, in previous line
    // some code

    Try the following:
    1) Use cc -misalign file.c
    2) Add #pragma pack(1) before your structures to pack them
    It's more likely the 1) helps
    Quang

  • Support package stacks: Do we need to import all SP in the stack?

    Hi all.
    We are about to import Support Package Stack 13 into our ERP 6.0 system. The SPS includes a lot of support packages for software components such as IS-OIL, IS-UT and other IS-*  components.
    These components are inactive in our system, and are not used. However, I know that the recommendation is to import the complete stack.
    I am therefore having some doubts if it is wise to import the IS-* related support packages.
    Please advise.
    Regards,
    Thomas

    Thank you for your feedback.
    However, I would like to ask if the only argument is to follow SAP recommendation? What risks are we running if we do not implement the IS component support packages?
    As the IS-* components are not active, I don't see how not importing these support packages will cause "inconsistence" in the system. Also, it would reduce the total number of support packages that needs to be included.
    I am generally positive to following SAP's recommendations, but in this case we are are in a situation where we need to lift the SAP system from SPS 8 to SPS 13 in one operation. That includes a massive amount of support packages, and possibly a lot more time than the timeframe we have available.
    Regards,
    Thomas

  • 64bit Solaris - how to enable it? Need server flag or d64 ??

    JRE 1.4.2
    Solaris 9
    To enable a 64bit server product, do I have to use any flags besides "-server" flag ?
    I can't seem to find any documentation on this. The closest thing I came across was the release notes documentation for 1.4.2 in its change history section under 1.4.0 where it mentions this:
    "The SolarisTM-SPARCTM platform edition of J2SDK 1.4.0 will support
    64-bit operation on 64-bit Sparc-v9 platforms when using the Java
    HotSpot Server VM. With a 64-bit address space, more than four gigabytes
    of heap memory is available. The Java HotSpot Server VM includes support
    for both 32-bit and 64-bit operations, and users can select either
    32-bit or 64-bit operation by using command-line flags -d32 or -d64,
    respectively.
    * Users of the Java Native Interface will need to recompile their
    code to be able to run it on the 64-bit VM.
    * There is no 64-bit support for the Java HotSpot Client VM. Only
    the Java HotSpot Server VM provides for optional 64-bit
    operation.
    * Users must install 64-bit Solaris support in order to run the
    virtual machine in 64-bit mode.
    * On older Sparcv9 systems, users must modify the file
    /platform/sun4u/boot.conf in order to enable 64-bit programs.
    See the text in the boot.conf file for more information."
    The full link:
    http://java.sun.com/j2se/1.4.2/docs/guide/vm/index.html
    but that is under JRE 1.4.0. Has anything changed since? do I still need the "-d64" flag or would the "-server" flag suffice.

    Hi
    Besides the 32bit installation, u will need to install the 64bit version.
    Add -d64. To confirm you have it, just do java -server -d64 -showversion
    http://java.sun.com/j2se/1.4.2/install-solaris-64.html
    http://java.sun.com/j2se/1.4.2/docs/guide/vm/index.html
    Hope this helps.

  • I need to flag a message for followup with a reminder

    Can you flag an email message in Microsoft Outlook with a reminder on an iPhone?

    Outlook reminders only work within outook. I use a service called Followupthen that sends me text reminders for emails I need to deal with. It doesn't require a particular email client. You may find it useful.

  • Ability to Flag *all* images in a Stack

    Hi,
    I shoot for HDR using auto-bracketing, and then auto-stack and collapse-all-stacks to have just the top (0ev) shot showing, and then navigate through the shots from a session in full screen to Pick them before using Refine.
    But, I then have to go back through all of the shots to find & expand the stacks that are picked to set the Pick flag for all of the other images in the stacks - it would be sooooo much easier if I could just set 'Pick' on all of the images with one keystroke!
    Please  ........?
    Gary

    I love a man with a sense of Humor
    Your the man!  Thanks so much.  I bracket all my shots and load them into the  HDR editor in Ps; my workflow will go so much smoother now.

  • Need a few hints for graph component Stacked bar

    Hi to all,
    JDeveloper11gR2
    i need a little step by step tutorial to create a stacked bar graph component to answer the following questions.
    which data table structure i need?
    which data structure i need? horizontal (columns stacking) or vertical (rows stacking)
    Will i need the hierarchical graph option in the creation wizard?
    I think the documentation unattended a litte bit the useful stacked graph component.
    Thank you very much.
    Best regards
    Gunnar
    Edited by: gkieck on Dec 14, 2012 12:06 AM

    ...

  • I need help understanding an alignment panic when calling mutex_init

    I am looking for help with a STREAM module that compiles and run under Solaris 10 on 32-bit and 64-bit Intel kernels but panics on a 64-bit Sarc kernel.
    I have isolated the panic to a data alignment issue when my init routine calls either the rwinit and mutux_init routines with a pointer to a krwlock_t or kmutex_t structure that is not 8 byte aligned.
    I am using "gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath)" from the Solaris 10 install CD's with the following options:
    gcc -Wall -fno-builtin -ffreestanding -nodefaultlibs -fpcc-struct-return -D_KERNEL -mno-app-regs -g -m64 -mcpu=v9 -D_SYSCALL32 -D_SYSCALL32_IMPL -D_ELF64 -D__sparcv9cpu -DSYSACCT -DC2_AUDIT
    (I know some of these are redundant)
    I have 4 locks along with a variety of other members defined in a structure used to by my driver code. If I manually arrange the structure to keep the lock variables on 8 byte boundries the module loads without a panic. However, if I let gcc handle the alignment or specifiy "__attribute__ ((aligned (8)))" on the lock variable definition the module panics on entry to the kernel rw_init or mutex_init routine with a BAD TRAP type 34 alignment error.
    At this point I am lost. I'm guessing this is a gcc/sparcv9 issue but I have no idea how to code this properly. I'm hoping someone can help shed some light on the problem.

    I found the problem. A shared header had a "#pragma pack(1)" with no matching "#pragma pack()". This was causing gcc to pack everything after the include.
    I'm still a little unclear why my "__attribute__ ((aligned (8)))" on the actual variable did not override the pragma ??? but at least I found the culprit.

  • REALLY NEED URGENT HELP with typedef struct char in LabVIEW

    Hi,
    So I am calling a DLL inside my LabVIEW VI.
    Inside the DLL, I have the following structure:
    typedef struct
          char string[21];
    } Geo_Tuple;
    Then I used it here in a function by calling:
    set_Geo_Coordinates(const File_or_Interactive State, const Input_or_Output Direction, const Geo_Tuple coordinates)
    (Note that File_or_Interactive and Input_or_Output are typedef enum.)
    So now, I am trying to implement this function in LV using the Call Function Node.
    However, it's not working --> const Geo_Tuple coordinates does not have the correct structure.
    So my question:
    How do I implement
    typedef struct
          char string[21];
    } Geo_Tuple;
    So that I can use it here: set_Geo_Coordinates(const File_or_Interactive State, const Input_or_Output Direction, const Geo_Tuple coordinates)
    Thanks!

    How have you configured your call library node?  To get a representation in LabVIEW of your Geo_Tuple type you'll need to create a cluster that contains 21 U8 elements, which you can do by creating an empty U8 array and wiring it to "Array to Cluster" set to 21 elements.  Connect this to the input side of the call library node.  On the output side, convert back to an array, and from there convert it to a string.

  • Production labels, Need to flag record when successfully printed.

    Hello,
    I am using CR2008 and I design a production label, this label goes to the floor to be made. My problem is that, there are orders entered all day long and labels need to be printed twice a day. When the query updates, it pulls the info of all day and the person printing labels cannot identify what has printed. I need to be able to flag or update a field in a table when label successfully prints.
    I would greatly appreciate your help.
    Thank You,
    Jose

    Jose,
    As long as you have UPDATE permissions in the database (or whomever would be running the report), you can use a Command to do this.
    It could look something like this...
    CREATE TABLE #Temp (OrderID INT)
    INSERT INTO #Temp(OrderID)
    SELECT OrderID FROM TableName WHERE Fields = Report Criteria
    UPDATE TableName SET PrintedFlag = 1
    WHERE OrderID IN (SELECT OrderID FROM #Temp)
    SELECT
    Fields For Report
    FROM  TableName
    WHERE OrderID IN (SELECT OrderID FROM #Temp)
    but unless you are comfortable writing SQL you should stay away from UPDATE, INSERT & DELETE statements... Actually anything other than a SELECT statement can damage your database if you don't know what you are doing.
    If you have access to a DBA, let them know what you are trying to do. Writing the necessary SQL should be piece of cake for someone who knows SQL.
    HTH,
    Jason

  • New to Dreamweaver and need help with menu alignment in IE

    Hi l,
    I am new to Dreamweaver, in fact this is my first ever website / question...
    I have just produced this site for a friend
    http://www.grantgibsondesign.com/A_Morrow1/
    I am happy with how everything looks in Firfox etc. however, with Internet Explorer my menu table alignment goes out the window!
    Can anybody suggest a quick fix?
    I produced it in dreamweaver CS3.
    Thanks in advance
    Gibo
    [Subject edited for clarity by moderator]

    I'm in the same boat that why I asked.  I ran it through browsershots too and everything looked fine:
    http://browsershots.org/http://www.grantgibsondesign.com/A_Morrow1/
    Even went back to IE 6.  Which is why I asked for a screenshot. If you can go back to the person who told you about the design flaw ask them for a screenshot.  Otherwise I can't really do much more than shoot in the dark.

  • Need Help about Vertical Align in TLF-

    I have added an InlineGraphicsElement in TextFlow which has some text in it. and i want to align the text verticalAlign.MIDDLE. ie. the text should be vertically aligned middle to the InlineGraphicsElement. rite now its bottom aligned. how can i make it to middle aligned like the attached image. please help me..?

    sabre150 wrote:
    So what makes you think that not using StringBuffer is the cause of the OP's problem?Just by experience. The main cause of resource hogs in Java is large string concatenation enclosed in a loop.
    I've just made the following experience :
    public class Test {
        public static void main(String[] args) {
            new Test().execute();
        private void execute() {
            long a, b, c;
            String value = "A123456789B123456789C123456789D123456789";
            String reply = "";
            StringBuffer buffer = new StringBuffer();
            a = System.currentTimeMillis();
            for (int i = 0; i < 5000; i++) { reply += value; }
            b = System.currentTimeMillis();
            for (int i = 0; i < 5000; i++) { buffer.append(value); }
            reply = buffer.toString();
            c = System.currentTimeMillis();
            System.out.println("Duration - concatenation = " + (b-a) + " / string buffer = " + (c-b));
    }Output :
    Duration - concatenation = 21295 / string buffer = 7

  • Memory fault trap handler

    I apologize in advance, as this is not strictly
    kernel related, except for trap handlers...
    I get a SIGBUS casting sockaddr to sockaddr_in,
    but only if sockaddr was declared on the stack.
    I am using Forte C/C++ for Sparc WS6U2.
    Getting right to the point, is there a way to have
    the compiler strictly align structs declared on the
    stack, similar to malloc always returning strictly
    aligned memory?
    Is there any other workaround, other than using
    -misalign (bad performance), or fixing each and
    every instance of a struct on the stack?
    When -misalign is used, can somebody confirm
    that a kernel mode trap handler is used to catch
    the memory fault and interpret byte-wise access
    instead of the usual SIGBUS?
    What is the name of the trap handler that would
    generate the SIGBUS due to bad alignment?
    How can it be observed with dbx, or is that
    impossible?
    Where are trap handlers documented?
    Please also see "need CC flag to align structs on stack"
    in the Forte C++ compiler discussion forum for more details.
    Thanks in advance,
    -Ralph

    Some partial answers to my own questions...
    Trap handling exists and is architecture specific. In at least some
    cases, the trap handler is known as #6. There is a paper on trap
    handling by Jim Moore: ftp://ftp.warwick.ac.uk/pub/solaris2/traps
    However, I am still curious about the hope for a cc flag that would
    align structs declared on the stack, similar to malloc'd memory.
    Did, does, will such a thing exist for Forte C/C++?
    -Ralph

  • Need Amount column to be Right Aligned in LOV asap

    Hi,
    I have a amount column in a custom LOV which needs to be right aligned. but in LOV, by default all columns come as left aligned..Pls provide a solution asap.
    Thanks,
    Puneet

    The column alignment depends on the type of data it displaying. Number columns are right aligned and string column are left aligned. this is default behaviour.
    Change datatype of column amount to Number. It will allign right.
    Thanks,
    Ram

  • Need help Aligning something...just can't get it.

    I can't seem to align the pricetotalstr in the simple prog I made below. If you can figure out what I need to do to align the pricetotalstr with the Amount column. It would be appreciated.

    Forgot to post the prog:
    //Collin
    //This program
    class JN9_4
              public static void main (String[] args)
                   //variables
                   int pots = 0;
                   int largeboxes;
                   int bigboxes;
                   int smallboxes;
                   double pricelarge;
                   double pricebig;
                   double pricesmall;
                   double totallarge;
                   double totalbig;
                   double totalsmall;
                   double pricetotal;
                   String pricetotalstr;
                   //literals
                   final double Pricelarge = 7.25;
                   final double Pricebig = 3.50;
                   final double Pricesmall = 1.00;
                   //input
                   pots = IO.getInt("How many pots are going to be shipped?");
                   //process
                   largeboxes = pots/9;
                   bigboxes = (pots%9)/4;
                   smallboxes = (pots%9)%4;
                   totallarge = largeboxes*Pricelarge;
                   totalbig = bigboxes*Pricebig;
                   totalsmall = smallboxes*Pricesmall;
                   pricetotal = totallarge+totalbig+totalsmall;
                   //output
                   pricetotalstr = IO.format('r', 8, pricetotal, 2);
                   IO.showMsg("Num \t Size \t Price \t\t Amount" +"\n"+
                             largeboxes+"\t 9 \t $"+Pricelarge+"\t\t $"+totallarge+"\n"+
                             bigboxes+"\t 4\t $"+Pricebig+"\t\t $"+totalbig+"\n"+
                             smallboxes+"\t 1\t $"+Pricesmall+"\t\t $"+totalsmall+"\n"+
                             "\t\t\t\t $"+pricetotalstr);
                   //done
                   System.exit(0);
    }

Maybe you are looking for

  • Can see library but it doesn't load up

    I've bought a new laptop and I'm trying to move my itunes stuff from my old laptop to my new one. They're both on the same network currently, sat next to each other on a desk, with the latest version of iTunes open on each laptop. Home sharing is tur

  • IPod Touch 4G Charging Problems

    The third-party charger that I have been using for a year stopped working. I eventually figured out it was the charger, not my PC or iPod. So I use my old Apple charger that came with my iPod which stopped working somewhere in mid 2012 early 2013 (go

  • HTTP/1.1 500 Internal Serve

    Trying to login with firefox 3.6.23 causes below. HTTP/1.1 500 Internal Server Error Date: Tue, 18 Oct 2011 20:50:15 GMT Server: Oracle-Application-Server-10g Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=iso-8859-1 28

  • Lumia 1520 - back arrow button and Windows button ...

    Hi, Can someone please tell me why the back button and the windows button have stopped working (2 of the three buttons at the bottom of the Lumia 1520)? The search function works fine by the way.  It is also causing the 'Listening' function to turn i

  • Check details about which products are installed in the Oracle Home

    I cheked one PDF: <epm-tips-issue 73-102> This command should return with details but giving some errors- 1) opatch lsinventory -oh /scratch/aime1/work/Oracle/Middleware/EPMSystem11R1 -jre /scratch/ aime1/work/Oracle/Middleware/jdk160_11 2) opatch ls