KDS v3.2.0 #pragma GCC pop_options broken

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KDS v3.2.0 #pragma GCC pop_options broken

1,159 Views
carlnormansuret
Contributor V

I have posted this question below in a related thread but have no answer, and I dont seem to be able to put a support ticket in anymore...

The compiler option of O0, O1, O2, Os in Debug mode 

I have some issues with my project using a struct that wont work correctly in release. Below I have fixed it by turning optmisation down to 0 for the struct but I am not 100% sure its pushing an popping the optmizations as the "correct way" is broken (still)... Anyone confirm if this is right, or, how I should do it knowing #pragma GCC pop_options is broken? I cannot get __attribute__((optimize("O0"))) to work, if someone can tell me how to add this attribute to a struct below that might help. 

 

<HEADER FILE>

typedef struct
__attribute__((__packed__))
{

   int value1;

   unsigned long value2;

   char string1;

}ramtable_s;

extern volatile ramtable_s RamTable;

 

 

<C FILE>

#pragma pack(push)
#pragma GCC optimize("O0")

volatile ramtable_s RamTable =
{

   .value1 = 0;

   .value2 = 10;

   .string1 = "TEST";

};

#pragma pack(pop)

 

PS the #pragma GCC optimize("O0") is 100% working in this case, but, im worried its staying at level 0 for the rest of the code and I am not sure how to prove / disprove this.

the other way to resolve this is to have some sort of SECTION defined and KEEP  it in the linker. 

0 Kudos
6 Replies

776 Views
bobpaddock
Senior Contributor III

Changing the optimization level via Prgam's is only supported in some of the compilers such as x86.

In the unsupported ones the directive is ignored.

The code unit needs compiled as a separate file with separate optimizations settings for that code unit in the Makefile.

opt0_file.o: CFLAGS += -O0

While that answer your question it is not your actual problem.

If changing the optimization level of the code is breaking or fixing something then there is a problem with something related to volatile.

Something that needs to be marked as such is not.

0 Kudos

776 Views
carlnormansuret
Contributor V

Thanks Bob, 

I wonder in KDS if i can add this into the properties of the project somewhere? I have never had to touch the makefile itself. So can I put this "opt0_file.o: CFLAGS += -O0" somewhere in KDS properties so it gets added to the makefile (or what ever).

You're right about the volatile being an issue, others developers have noted this problem on the forums and the KDS developers have not done anything about it.

There is also a problem with the pop as I said which I think they're aware of but have also not fixed.

I have no idea how to reach out to the KDS developers to let them know of potentially catastrophic issues with the tool chain.

0 Kudos

776 Views
bobpaddock
Senior Contributor III

If the code show above is real code I'm surprised it runs at all.

The typedef says 'char string1' then is initialized as tho it is a pointer to a string as if it was 'char *string1'.

The push needs to specify the new alignment:

/*
* Push current alignment rules to internal compiler stack then
* force 1-byte alignment boundary:
*/
#pragma pack(push,1)

/* stuff */

/* Restore original alignment rules from stack: */
#pragma pack(pop)

I do not know the answer to your KDS question about how to do it as the KDS level.


No idea how to easily find the volatile issue that may be in KDS.

When the problem goes away for you is the file that is being set to -O0  KDS source code  file (not a file created by other entities)?

If you feel there is a problem with the actual GCC compiler, which is rare these days, create a simple test case that demonstrates the problem,

then submit the preprocessed version to the GCC bug tracker:

# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E  -I. $(CFLAGS) $< -o $@

0 Kudos

776 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Carl,

What about the issue when you use the structure?

How about add the size of alignment bytes .

#pragma pack(n)

Why are all of my pragmas being ignored as "unknkown"?   

BR

Alice

0 Kudos

776 Views
carlnormansuret
Contributor V

Sorry, you lost me. Not sure what you're saying / asking... There is a problem with Volatile, pop, and, I dont know how to use attribute as show to make that struct not optimized.

0 Kudos

776 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Carl,

Sorry , could you please tell me how to reproduce your problem on my side,

then I can  report it to KDS development team . Includes the below informations :the chip part number, project,

the wrong result and what's result it  should be , thanks !

BR

Alice

0 Kudos