Re: C Metaprogramming
Thats very interesting, thanks for sharing. mike On Tue, Jun 19, 2012 at 4:41 AM, Daniel Santos wrote: > Yes, my topic sounds crazy huh? But you guys made it possible when you > started optimizing out constant function pointers. (Thank you!!) This > didn't mature to "full power" until 4.6.? (works in 4.6.2, not sure > about earlier 4.6). Now that you can populate a struct with const > pointers to inline functions and pass a pointer to that struct to a > generic inline function, full C type-injection is now possible. (Well, > you probably didn't need to be able to do it via a struct, but it sure > cleans up the interface). > > Example here: http://lwn.net/Articles/500757/ (patches last sent to LKML > on June 7th, don't have them posted elsewhere atm, sorry) > > However, the process of verifying that your calls by > constant-function-pointer (much less, one that is a struct member) is > one of examining the generated code, since __builtin_constant_p will > always return zero when passed a function pointer (or any pointer I've > given it thus far). This simple program demonstrates the problem: > > #include > static inline int myfunc(int a) { > return a + 42; > } > > static int (*const myptr)(int) = myfunc; > > int main(int argc, char *argv[]) { > printf("is const = %d\n", __builtin_constant_p(myptr)); > /* same result if I dereference it: __builtin_constant_p(*myptr) */ > } > > So before filing any feature request bugs, I figured I should bring my > discussion here first, as I believe some enhancements to gcc can better > enable this type of programming. > > First off, we need a mechanism to verify constness of a function pointer > at build time and generate an error when the value is non-const, similar > to the construct: > > #define BUILD_BUG_ON_NON_CONST(arg) \ > do { \ > extern void __value_non_constant(void) \ > __attribute__((error("value not constant"))); \ > if (!__builtin_constant_p(arg)) \ > __not_constant_error(); \ > } while (0) > > Second, it will be helpful to have a mechanism to generate a -Winline > warning when a function call by pointer cannot be inlined. Obviously, > this is impossible if you can't first determine that it's a const > function pointer and resolve that to the actual function. I'm sorry to > say that I don't have a suggestion for doing this other than some > __builtin_isinlineable() type of function (that accepts a function > pointer). Perhaps solving the above problem and assuring that, after > this test for function pointer constness succeeds and the const function > pointer can be resolved to an inline function, the compiler can just > emit a warning as it would when a normal function call to an inline > cannot be inlined. Here's an example: > > #include > static inline int myfunc(int a) { > return a + 42; > } > > static inline void jack(int (*const fnptr)(int)) { > /* macro from above, except working for function pointers */ > BUILD_BUG_ON_NON_CONST(fnptr); > > /* if the above test passes, any inability to inline myfunc should > * produce a -Winline warning > */ > fnptr(0); > } > > int main(int argc, char *argv[]) { > jack(myfunc); > } > > Thanks > Daniel -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3
Re: The C++ conversion branch has been merged into trunk
Thats great, I have also tried in the distant past do so C++ compilation. Will have to get back on the bandwagon. mike On Wed, Aug 15, 2012 at 2:05 AM, Diego Novillo wrote: > > I have committed rev 190402, which merges the cxx-conversion branch into > trunk. Thanks to everyone who provided review feedback and tested the > branch. > > While we have tested the changes pretty thoroughly, we will monitor results > from testers for any new failures introduced by these changes. Please CC > myself and Lawrence on any issues that may be related to the C++ changes. > > As discussed in http://gcc.gnu.org/ml/gcc-patches/2012-08/msg00711.html, > there are no functional changes to the compiler. We tried very hard to limit > the amount of API changes we introduced to minimize merge conflicts. > > Now that the changes are in trunk we will start changing the APIs to take > advantage of the re-written data structures. > > I have also committed the changes to the home page news section and 4.8 > changes to reflect the new implementation language. > > > Thanks. Diego. -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3
Re: The C++ conversion branch has been merged into trunk
to be clear, I have also tried in the distant past do some C++ compilation of the gcc. I had some ideas for making c++ interfaces to the classes and some code. Also for converting some macros into inline functions for type safety. mike On Wed, Aug 15, 2012 at 6:50 AM, Mike Dupont wrote: > Thats great, > I have also tried in the distant past do so C++ compilation. Will have > to get back on the bandwagon. > mike > > On Wed, Aug 15, 2012 at 2:05 AM, Diego Novillo wrote: >> >> I have committed rev 190402, which merges the cxx-conversion branch into >> trunk. Thanks to everyone who provided review feedback and tested the >> branch. >> >> While we have tested the changes pretty thoroughly, we will monitor results >> from testers for any new failures introduced by these changes. Please CC >> myself and Lawrence on any issues that may be related to the C++ changes. >> >> As discussed in http://gcc.gnu.org/ml/gcc-patches/2012-08/msg00711.html, >> there are no functional changes to the compiler. We tried very hard to limit >> the amount of API changes we introduced to minimize merge conflicts. >> >> Now that the changes are in trunk we will start changing the APIs to take >> advantage of the re-written data structures. >> >> I have also committed the changes to the home page news section and 4.8 >> changes to reflect the new implementation language. >> >> >> Thanks. Diego. > > > > -- > James Michael DuPont > Member of Free Libre Open Source Software Kosova http://flossk.org > Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com > Contributor FOSM, the CC-BY-SA map of the world http://fosm.org > Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3
Re: [OT] Control Flow Graph(CFG) into Abstract Syntax Tree(AST)
thanks for sharing, will check this out. mike On Fri, Sep 14, 2012 at 9:05 PM, James Courtier-Dutton wrote: > Hi, > > I know most compilers go from AST to CFG. > I am writing a decompiler, so I was wondering if anyone knew of any > documents describing how best to get from CFG to AST. > The decompiler project is open source. > https://github.com/jcdutton/libbeauty > > The decompiler already contains a disassembler and a virtual machine > resulting in an annotated CFG. It uses information gained from using a > virtual machine to annotate the CFG. Another use of the VM will be to > help analyze self modifying code. > > The decompiler can output C source code form the CFG, but it is not > easy to understand the result due to lack of structure such as for {} > loops. > I wish to create an AST from the CFG in order to be able to output for > {}, while {} and if...then...else structure. > > The CFG to AST step seems a little complicated, so I was looking for > some pointers to how best to do it to save me re-inventing the wheel. > > Kind Regards > > James -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3
Re: Proposed C++ optimization with big speed gains with big objects
Hi, I think what you want is a custom allocator : http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html http://www.boost.org/doc/libs/1_45_0/doc/html/interprocess/allocators_containers.html http://stackoverflow.com/questions/2439536/strategy-to-allocate-free-lots-of-small-objects hope that helps, mike On Mon, Sep 24, 2012 at 1:02 PM, _ wrote: > Hi guys > > I wana discuss proposed optimization step(optional switch?) to c++ > compiller that would make old and new code in some cases order of > magnitude faster by just pure recompilation. > > ...After all those attempts to store anything via = without waste I > think that compiller should do "placement new" transparently for us > whenever he encounters = on movable object. Instead of forcing us to > implement zillion && operators that solve only heap side of problem. > Deciding what kind of "this" object should use is easy since static > analysis deciding what object is movable is already part of new > compiller support for &&. > > Skyscrapper city[1000]; // instead of temp > city[1] = Skyscrapper("Empire State Building"); // compiller should > use &city[1] as this pointer > > This would fix heap and static(which && can't) waste = zero alloc/copy. > Why is static mem waste equally if not more important? Majority of > objects are small thus majority of their memory is static. > > Benchmark results in article www codeproject > com/Articles/453022/The-new-Cplusplus-11-rvalue-reference-and-why-you > > I am actively attemting to test this change in gcc > But I am kinda lost in gcc code. maybe somebody from you guys can > trow togethed this auto placement new instead of temp a lot faster > since you know your > code. > I just can't wait to see the numbers of speed gained from untouched c++ code. > Like running benchmark code from my article but with such compiller > changes. > > I love what you guys do. Keep up the great opensource work. > > Best Regards Ladislav [Unemployed] > neuralll[@]gmail[.]com -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3
gcc master build problems
Hi there, on the gcc buildfarm : /home/h4ck3rm1k3/experiments/gcc-build/ I am having problems with a standard build of the gcc using the 4.5.1 compiler. 1. ./morestack.vis:1: Error: junk at end of line, first unrecognized character is `:' h4ck3rm1k3@gcc10:~/experiments/gcc-build/x86_64-unknown-linux-gnu/32/libgcc$ /home/h4ck3rm1k3/experiments/gcc-build/./gcc/xgcc -save-temps -B/home/h4ck3rm1k\ 3/experiments/gcc-build/./gcc/ -B/home/h4ck3rm1k3/install/x86_64-unknown-linux-gnu/bin/ -B/home/h4ck3rm1k3/install/x86_64-unknown-linux-gnu/lib/ -isystem /h\ ome/h4ck3rm1k3/install/x86_64-unknown-linux-gnu/include -isystem /home/h4ck3rm1k3/install/x86_64-unknown-linux-gnu/sys-include-g -O2 -m32 -O2 -g -O2 -D\ IN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -\ g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fpic -mlong-double-80 -I. -I. -I../../.././gcc -I../../../../gcc/libgcc -I../../../../gcc/libgcc/. \ -I../../../../gcc/libgcc/../gcc -I../../../../gcc/libgcc/../include -I../../../../gcc/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_\ TLS -o morestack.o -MT morestack.o -MD -MP -MF morestack.dep -c -xassembler-with-cpp -include morestack.vis ../../../../gcc/libgcc/config/i386/morestack.S ./morestack.vis: Assembler messages: ./morestack.vis:1: Error: junk at end of line, first unrecognized character is `:' workaround compile like this ; /home/h4ck3rm1k3/experiments/gcc-build/./gcc/xgcc -c -B/home/h4ck3rm1k3/experim\ ents/gcc-build/./gcc/ -B/home/h4ck3rm1k3/install/x86_64-unknown-linux-gnu/bin/ -B/home/h4ck3rm1k3/install/x86_64-unknown-linux-gnu/lib/ -isystem /home/h4ck3\ rm1k3/install/x86_64-unknown-linux-gnu/include -isystem /home/h4ck3rm1k3/install/x86_64-unknown-linux-gnu/sys-include-g -O2 -m32 -O2 -g -O2 -DIN_GCC \ -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -g -DIN_LI\ BGCC2 -fbuilding-libgcc -fno-stack-protector -fpic -mlong-double-80 -I. -I. -I../../.././gcc -I../../../../gcc/libgcc -I../../../../gcc/libgcc/. -I../../.\ ./../gcc/libgcc/../gcc -I../../../../gcc/libgcc/../include -I../../../../gcc/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_TLS -o mo\ restack.o -MT morestack.o -MD -MP morestack.s Then the file is empty libgcc.map, it is generated by some complex sed script, but it is failing. /usr/bin/ld:libgcc.map:1: syntax error in VERSION script anyone else had this problem? mike -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3
bug report : -save-temps and stdin
using a very recent : gcc version 4.8.0 20121021 (experimental) (GCC) h4ck3rm1k3@gcc10:~/experiments/build/glibc$ echo "int x;" | g++ -save-temps -x c - cc1: error: unrecognized command line option ‘-.i’ this causes problems compiling glibc with -save-temps. is this known? should I report a bug? any ideas on fixing it, I might be able to do so, it should be simple. mike -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3
Re: bug report : -save-temps and stdin
Well in this case, what about a random temp file name? tmpfile ? something with the timestamp as well. I would like to have those files if possible. would that be acceptable? mike On Sun, Oct 28, 2012 at 6:40 PM, Joseph S. Myers wrote: > On Sun, 28 Oct 2012, Mike Dupont wrote: > >> is this known? should I report a bug? any ideas on fixing it, I might >> be able to do so, it should be simple. > > I think the fix should be to give an early error message for compiling > from stdin with -save-temps, and then stop the compilation because there's > nowhere to save the intermediate files (given the lack of an input file > name). > > -- > Joseph S. Myers > jos...@codesourcery.com -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3
Re: bug report : -save-temps and stdin
On Mon, Oct 29, 2012 at 11:19 AM, Jonathan Wakely wrote: > On 29 October 2012 09:25, Mike Dupont wrote: >> Well in this case, what about a random temp file name? tmpfile ? >> something with the timestamp as well. >> I would like to have those files if possible. would that be acceptable? > > Why not just write the source to the temp file then invoke GCC on it? Well I considered that. It would be a trivial change to the glibc makefile, in many places. > Why add that into GCC itself when it's trivial to do externally? well i thought it might be a useful feature, what about allowing the user to speficy the filename and if it is missing, then we can abort? -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3
Re: bug report : -save-temps and stdin
On Mon, Oct 29, 2012 at 11:20 AM, Jonathan Wakely wrote: > Creating the temp file yourself has the advantage you know what the > name is, whereas if GCC creates it you need to look for new files or > check timestamps to find what name it used. so we can have three options that I would suggest : 1. no parameters passed fails when there is no filename. (is good default behaviour) 2. filename specfied, it is used. (is good for makefile authors) 3. random filename specfied, it will be used, (is good for cflags) -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3
Re: bug report : -save-temps and stdin
On Mon, Oct 29, 2012 at 2:57 PM, Richard Biener wrote: > Alternatively, inform the user that -save-temps is ignored and continue ... > (I can see people annoyed by foreign Makefiles and tying to get at > preprocessed > source with CFLAGS="... -save-temps") that also makes sense, and would be more useful than a crash or abort. mike -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3
Re: A cscope-like gcc plugin
Sounds great, thanks for sharing! On Wed, Dec 5, 2012 at 3:14 AM, Yunfeng ZHANG wrote: > Hi all: > I'm pleased to announce my gcc plugin on gcc-4.6.3 has been released, it > collects data from gcc compilation stage and dump them to sqlite-database just > like cscope, but with later enhancement. > 1) Function alias. To linux, later code often makes you confusion. > f_ops fs = { .open = ext2_open, }; > void foo(void) > { > fs.open = ext2_open; > ... > fs.open(); // << which function will be called, where is it? > } > The feature treats `ext2_open' as an alias of `open'. So when you search > `open', jump to `ext2_open'. Of course, you can get `ext2_open' is called by > `foo' reversely. > 2) Whether current line is skipped by `#ifdef/#if'. > 3) Extract defintion beyond macro tokens. > > Tested projects are mainly linux-2.6.35 (mips). Other source compiled include > gcc-4.6.3, glibc-2.13, gdb-7.4 of mips, qemu-1.1.1 of x86. > > Go from doc.txt of attachment, or http://gccsymdb.googlecode.com/svn/tags/v3/. >Yunfeng Zhang -- James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3