[lttng-dev] [PATCH lttng-ust] Fix: remove weak attribute from __start___tracepoints_ptrs and __stop___tracepoints_ptrs

Thibault, Daniel Daniel.Thibault at drdc-rddc.gc.ca
Tue Jun 10 13:27:19 EDT 2014


----------------------------------------------------------------------
Date: Tue, 10 Jun 2014 09:13:54 +0200

>> Does it work well if the program and/or libraries do the following:
>>
>> - they include tracepoint.h,
>> - but they don't contain any tracepoint (so there is technically no
>>    _tracepoint_ptrs section)
>>
>> Has this case been tested ? I remember that the weak was there for this
>> peculiar corner case.
>
>I tested it exactly the way you described, and yes, it works.
>*HOWEVER*, if prior to including tracepoint.h the program also #defines 
>TRACEPOINT_DEFINE, *THEN* we have the problem you described:
>
>root at kmeter1:~# cat foo.c
>
>#define TRACEPOINT_DEFINE
>#include <lttng/tracepoint.h>
>
>int main(void)
>{
>   printf("Hello world!\n");
>}
>root at kmeter1:~# gcc foo.c -llttng-ust -ldl
>/tmp/cc92SYHX.o: In function `__tracepoints__ptrs_init':
>foo.c:(.text+0x39a): undefined reference to `__stop___tracepoints_ptrs'
>foo.c:(.text+0x39e): undefined reference to `__stop___tracepoints_ptrs'
>[...]
>/tmp/cc92SYHX.o:foo.c:(.text+0x44a): more undefined references to 
>`__start___tracepoints_ptrs' follow
>/usr/lib/gcc/powerpc-linux/4.7.2/../../../../powerpc-linux/bin/ld: 
>a.out: hidden symbol `__stop___tracepoints_ptrs' isn't defined
>/usr/lib/gcc/powerpc-linux/4.7.2/../../../../powerpc-linux/bin/ld: final 
>link failed: Bad value
>collect2: error: ld returned 1 exit status
>
>Re-adding the weak attribute "fixes" this (though it leaves us with a 
>much bigger issue, in my opinion).
>
>However, I'm not sure whether:
>
>a) this is really a use case (defining TRACEPOINT_DEFINE and then not 
>really defining any), and even so, whether
>
>b) what we have with the weak attribute is really what we want. In the 
>end, we would be defining a function with __attribute__((constructor)) 
> (oh wait, potentially even more than one!) without actually having any 
>tracepoint available. OK, the above complaints are probably not the most 
>intuitive in the world, but isn't that better than an application 
>silently "failing" (to provide any tracepoint) at runtime?
>
>After all, the issue with the above messages is about the linker trying 
>to resolve those symbols; but that's because they are used by 
>__tracepoints__ptrs_init() and friends, not because they are merely 
>declared.
>
>Any thoughts?
>
>Gerlando
----------------------------------------------------------------------

   If the issue is to protect against TRACEPOINT_DEFINE not being 'fulfilled' before hitting lttng/tracepoint.h, maybe tracepoint.h should check for TRACEPOINT_PROVIDER in addition to TRACEPOINT_DEFINE.

Daniel U. Thibault
Protection des systèmes et contremesures (PSC) | Systems Protection & Countermeasures (SPC)
Cyber sécurité pour les missions essentielles (CME) | Mission Critical Cyber Security (MCCS)
RDDC - Centre de recherches de Valcartier | DRDC - Valcartier Research Centre
2459 route de la Bravoure
Québec QC  G3J 1X5
CANADA
Vox : (418) 844-4000 x4245
Fax : (418) 844-4538
NAC : 918V QSDJ <http://www.travelgis.com/map.asp?addr=918V%20QSDJ>
Gouvernement du Canada | Government of Canada
<http://www.valcartier.drdc-rddc.gc.ca/>



More information about the lttng-dev mailing list