ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • GNU Compiler __attribute__
    잡다 2014. 6. 19. 09:17
    • __attribute__((__used__))
      • 컴파일러가 코드를 최적화 할 때, 사용되지 않은 변수라 하더라도 제거하지 않도록 한다
      • "unused variable" 관련 compile warning을 방지
    • __attribute__((__aligned__(x)))
      • 변수가 위치하는 메모리의 주소를 x의 배수로 정렬한다
      • e.g) __attribute__((__aligned__(sizeof(long))))
    • __attribute__((__packed__))
      • 구조체 변수에대한 메모리를 할당 할 때, 기본적인 align 규칙(보통은 word, 4 bytes)을 따르지 않고, 실제 데이터의 크기 만큼만 메모리를 할당 하도록 한다
    • __attribute__((__section__(x)))
      • 변수가 ELF 오브젝트 내부에 x라는 이름을 갖는 특별한 섹션 안에 만들어지도록 한다
      • 주로 kernel 초기화 시에만 필요한 코드들을 .init.xxx section에 위치시키고, 사용 후에는 제거(free)하여 가용 메모리를 늘리는 방법으로 이용된다
      • 또한 이렇게 특정 section에 코드들을 위치시키는 방법은, code의 locality를 높여 instruction cache의 hit rate가 높아질 가능성(pipeline broken rate가 낮아질 가능성)이 있다
      • e.g.) __attribute__((__section__(".init.setup")))

    # Practical Example #
    (kernel/include/linux/init.h)
    /*
     * Only for really core code.  See moduleparam.h for the normal way.
     *
     * Force the alignment so the compiler doesn't space elements of the
     * obs_kernel_param "array" too far apart in .init.setup.
     */
    #define __setup_param(str, unique_id, fn, early) \
    static const char __setup_str_##unique_id[] __initconst \
    __attribute__((__aligned__(1))) = str; \
    static struct obs_kernel_param __setup_##unique_id \
    __attribute__((__used__)) \
                    __attribute__((__section__(.init.setup))) \
    __attribute__((aligned((sizeof(long))))) \
    = { __setup_str_##unique_id, fn, early }

    #define __setup(str, fn) \
    __setup_param(str, fn, fn, 0)





    http://yonomi.tistory.com/45 에서 퍼옴

    '잡다' 카테고리의 다른 글

    간단한 포토샵  (0) 2014.07.21
    Raw socket  (0) 2014.06.28
    Mac Address, 제조회사  (0) 2014.06.27
    [vi명령어] 자동정렬 / 단어찾기 / 도스저장  (0) 2014.06.25
    과제 : 문자열치환  (0) 2014.04.08
Designed by Tistory.