#qi-hardware IRC log for Thursday, 2016-05-12

whitequarkDocScrutinizer51: set_transient_window02:05
larscwhitequark: you always know these things. Do C compilers have rules for alignement of arrays that puts the start of the array at an address that is more aligned than the array entry size?08:28
whitequarkas far as I know, the array entry size does not matter, only whether the members go in the right places08:30
whitequarkconsider this: if you are allocating memory for an array (or a single struct, even) with malloc, malloc is not going to give you highly aligned memory08:31
whitequarkthere's no reason the linker should08:31
larscI have an array of pointers08:31
whitequark(and malloc will easily give you memory that's not aligned enough for some operations, such as SSE, which needs 16-byte alignment, but malloc will commonly gve you 8)08:31
larscif I have only one entry it's simply aligned to the pointer size08:31
larscbut if I have more it is aligned at a larger size08:32
whitequarkhow do you determine how is it aligned?08:32
larscup to 4 times the pointer size08:32
whitequarkI think this is a compiler-specific optimization08:32
larscwhat I'm trying to do is to put them in a special section, so I don't have to maintain a global list of all these pointers08:33
larscand what I'm seeing right now is that there are sometimes gaps08:33
larscnothing that can't be handled, but still not so nice08:33
larscor do you think this is a bad idea in general?08:34
whitequarkyes, to do this you need to explicitly call out the alignment on the global08:34
whitequarkno, it's a perfectluy fine idea08:34
whitequarklibc does this08:34
whitequarkfor .init/.fini08:34
whitequarkjust use __attributes__((align(sizeof(void*))))08:34
whitequarkAn explicit alignment may be specified for a global, which must be a power of 2. If not present, or if the alignment is set to zero, the alignment of the global is set by the target to whatever it feels convenient. If an explicit alignment is specified, the global is forced to have exactly that alignment. Targets and optimizers are not allowed to over-align the global if the global has an assigned section. In this case, the extra alignment c08:35
whitequarkexactly describes your use case08:35
larscok, thanks, that's quite helpful08:36
larscok, works perfectly, with explicit alignment the gaps are gone08:41
larscDo you know how portable such an approach is? This is for libsigrok08:43
whitequarkthis will work on gcc and clang08:52
whitequarkthe code to put it into a section is just as portable as the alignment attribute08:52
whitequarkso this specific part creates no new problems08:52
larscI mean the approach of using sections as arrays, do you can think of any platform where it will break08:54
whitequarkyou'll have to use __declspec(allocate)08:55
pcercuei< whitequark> just use __attributes__((align(sizeof(void*))))08:57
pcercueinot portable08:57
pcercueidammit, you just said it08:57
pcercueiI should read to the end :)08:58
larscwith it's lack of support for current C standards msvc is probably not a target anyway08:59
wpwrakeverything seems to converge to gcc anyway09:02
larscwhitequark: does this look ok to you? https://github.com/analogdevicesinc/libsigrok/commit/0a66432e5cd34bf8b6d9d144b0a7ca182b290816#diff-88d499a1a7ecc6d02d08a96525e502e5 09:14
larscand https://github.com/analogdevicesinc/libsigrok/commit/0a66432e5cd34bf8b6d9d144b0a7ca182b290816#diff-7af547b52769371de74af0bfca268a6209:14
whitequarkI don't see anything wrong with it09:21
larscok, thanks.09:22
pcercueilarsc, GCC adds the __start_$(section) / __stop_$(section) symbols automatically?10:07
whitequarkdoes it?10:28
whitequarkI'm pretty sure it doesn't, that's the default glibc linker script10:28
whitequarkyou might want to check that on non-glibc systems10:28
DocScrutinizer05to avoid any gaps, wrap the whole data section up into one hige struct10:32
DocScrutinizer05so it becomes one entity without gaps in between10:33
wpwrakwhitequark: i'd also be surprised if the compiler did that. at least i never encountered such10:35
wpwrakDocScrutinizer05: the whole idea is to be able to distribute those things :)10:35
whitequarkDocScrutinizer05: doesn't work if the whole point is to assemble it from multiple files10:35
wpwrakand it's a very well-established practice to do this. e.g., the linux kernel heavily makes use of this10:36
DocScrutinizer05but then you need to depend on the linker (or compiler *maybe*) since you can't coordinate stuff across files10:36
larscwell, it's definitly not the compiler because the compiler can't do that10:36
DocScrutinizer05wpwrak: this?10:36
DocScrutinizer05larsc: that's what I think too10:37
whitequarkyes. you need to depend on the linker.10:37
whitequarkif you don't provide your own linker script, the default linker script does something like this10:37
wpwrakDocScrutinizer05: this = special sections to collect lists of items10:37
whitequarkalternatively, you can go the crtbegin.o/crtend.o way10:37
whitequarkwhere you put a sentinel into a begin.o file and an end.o file10:38
whitequarksince linkers assemble sections in the order that they appear on the command line10:38
whitequarkthis is somewhat more portable than depending on specific glibc linker script10:38
whitequarklarsc: I think __attribute__((constructor)) will allow you to do the same without the mess of working with sections directly10:39
whitequarki.e. it will work on all practical ELF platforms regardless of libc10:40
whitequarkoh and __attribute__((constructor)) also works on OS X10:41
whitequarksoo... i think you're covered, really10:41
wpwraklinker scripts are a bit suckish if you only want to change some small detail, like adding a new set of sections, but then you have to do all the rest as well. and often enough, much of the rest doesn't really make sense to you.10:42
larschm I don't like constructor that much10:45
wpwrakwhitequark: but attribute((constructor)) means that it gets executed, no ? so that wouldn't work in lars' case10:45
whitequarkit will get executed and register itself in some global linked list or w/e10:45
larscwell you can have a function that adds things to a linked list or whatever10:45
wpwrak(at least no without a detour)10:45
larscbut I don't like that10:46
whitequarkit's cleaner because you don't rely on __start and otherwise it's the same thing10:46
larscat least as long as long as the section approach works10:46
whitequarkglobal constructors are generally evil but if the only thing you need is to set a single pointer10:46
whitequarktheyre ok10:46
larscit's hard to find actual documentation on the __start __stop symbols10:47
larscI was searching how to add new sections to the linker script, without re-writing the default linker script and that's what I found instead10:48
whitequarkthis will break on OS X.10:49
whitequarksince OS X has no linker scripts10:49
whitequarkbut, OS X supports constructor attribute10:49
whitequark(anything that supports C++ properly does)10:49
wpwraklarsc: from the ld documentation: "If the linker cannot recognize the format of an object file, it will assume that it is a linker script. A script specified in this way augments the main linker script used for the link"10:53
whitequarklarsc: yes. either of those works. or just use constructor.10:54
larscwpwrak: yes, it's terrible11:03
larscor is it?11:03
wpwraklarsc: this looks as if it was the answer to your question of how to add things to a linker script without having to rewrite the whole mess11:04
wpwrak(note: just spotted this, so i don't know how well it works in practice)11:05
wpwrakalso, if mac os x really has no linker scripts, and you care about supporting that platform, then constructors may indeed be the only way11:05
whitequarkwpwrak: os x has hardcoded start/end symbols11:28
whitequarktheyre just... different11:28
whitequarkyou could use constructors and work anywhere c++ and gcc-like attributes work, which is a lot of places11:28
whitequarkand never think about that shit again11:28
larscwpwrak: it looks as if you put INSERT AFTER $section into your custom linker script it wil also only augment the default11:47
larscwhitequark: but micro optimizations!11:48
whitequarkhave you *seen* how much shit the dynamic linker does11:49
larscluckily I never had to11:51
whitequarkyou can start by stracing it11:52
whitequarkanything dynamically linked11:52
DocScrutinizer05get towels for the bleeding eyes?11:52
--- Fri May 13 201600:00

Generated by irclog2html.py 2.9.2 by Marius Gedminas - find it at mg.pov.lt!